home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / DATABASE / SSQL31B.ZIP;1 / INSTDOC.EXE / SSQL.DOC < prev   
Encoding:
Text File  |  1992-07-19  |  214.9 KB  |  5,754 lines

  1.  
  2.  
  3.  
  4.                                      SSQL
  5.                                   VERSION 3.1
  6.  
  7.  
  8.                     COPYRIGHT (C) 1987-1992 BY STEVE SILVA
  9.     
  10.                             SILVAWARE
  11.                             P.O. Box 35071
  12.                             Phoenix, AZ 85069-5071
  13.  
  14.         Special thanks to the hard-working students in CIS425 at the
  15.         DeVry Institute of Technology, Phoenix, Arizona.
  16.  
  17.      *********************************************************************
  18.      *** THE LATEST VERSION IS AVAILABLE THROUGH:                      ***
  19.      *** The SilvaWare BBS (602) 945-6181 (Details on page INTRO-12)   ***
  20.      *** The SQLBBS   (312) 589-0508 (Details on page INTRO-13)        ***
  21.      *** CompuServe in the IBMAPPS forum under Databases               ***
  22.      *********************************************************************
  23.  
  24.      *********************************************************************
  25.      *** Do you have a question?  I enjoy hearing from you.  The       ***
  26.      *** fastest response is by contacting my BBS (see page INTRO-12)  ***
  27.      *** or on CompuServe (73177,2771). You can also contact me        ***
  28.      *** (Steve Silva) by mail.                                        ***
  29.      *********************************************************************
  30.  
  31.      *********************************************************************
  32.      *** IMPORTANT NOTE FOR PRINTERS!!!!                               ***
  33.      *** It is assumed that your printer can print the extended        ***
  34.      *** character set.  If it can't, the samples of windows and such  ***
  35.      *** won't look the way they should.                               ***
  36.      *********************************************************************
  37.  
  38.      *********************************************************************
  39.      *** FOR A COPY OF THE ORDER FORM, TYPE:                           ***
  40.      *** COPY ORDER.FOR PRN                                            ***
  41.      *** CREDIT CARDS NOW ACCEPTED. SEE ORDER.FOR FOR DETAILS          ***
  42.      *********************************************************************
  43.  
  44.      *********************************************************************
  45.      *** >> UNIX VERSION NOW AVAILABLE!!!!! <<                         ***
  46.      *** See INTRO-15 for details.                                     ***
  47.      *********************************************************************
  48.  
  49.      *********************************************************************
  50.      *** If you have a PC XT or compatible, SSQL may run too slow. Use ***
  51.      *** SSQLENG directly.  See INTRO-4, WORD-1, SCRIPT-1 for info.    ***
  52.      *********************************************************************
  53.  
  54.      
  55.  
  56.  
  57.                                  TABLE OF CONTENTS
  58.          
  59.         OVERVIEW
  60.             Enhancements From Earlier Versions.................INTRO-1
  61.             The Cost of These Wonderful Things.................INTRO-2
  62.             The Future of SSQL.................................INTRO-3
  63.             The Components of SSQL.............................INTRO-4
  64.         Installation...........................................INTRO-5
  65.         Fine-Tuning............................................INTRO-5
  66.         Start Up Options.......................................INTRO-5
  67.         Quick Start............................................INTRO-6
  68.         The Basics of the SSQL Environment.....................INTRO-6
  69.         Differences In The Registered Version..................INTRO-7
  70.         Permission to copy ....................................INTRO-9
  71. ********LICENSE AGREEMENT - PLEASE READ .......................INTRO-9
  72.         SSQL Specifications....................................INTRO-10
  73.         Contents of Disk ......................................INTRO-10
  74.         dBase Compatibility ...................................INTRO-10
  75.         Key Words Needed to Understand the Documentation.......INTRO-11
  76.         Syntax Diagrams .......................................INTRO-12
  77.         SilvaWare BBS - latest version and support too.........INTRO-12
  78.         SSQLBBS - An excellent BBS in the Chicago area.........INTRO-13
  79.         UNIX VERSION AVAILABLE!!...............................INTRO-15
  80.         
  81.         The Text Editor........................................ENV-1
  82.                 Block Commands.................................ENV-1
  83.                 Cursor Movement Commands.......................ENV-1
  84.                 Insert & Delete Commands.......................ENV-1
  85.                 Miscellaneous Editor Commands..................ENV-2
  86.         File
  87.                 Open...........................................ENV-2
  88.                         The File Dialog Box....................ENV-2
  89.                 New............................................ENV-3
  90.                 Save...........................................ENV-3
  91.                 Save As........................................ENV-4
  92.                 Input..........................................ENV-4
  93.                 Change Dir.....................................ENV-4
  94.                 Print..........................................ENV-5
  95.                 DOS Shell......................................ENV-5
  96.                 Exit...........................................ENV-5
  97.         Edit
  98.                 Undo...........................................ENV-5
  99.                 Cut............................................ENV-6
  100.                 Copy...........................................ENV-6
  101.                 Paste..........................................ENV-6
  102.                 Show Clipboard.................................ENV-6
  103.                 Clear..........................................ENV-6
  104.         Search
  105.                 Find...........................................ENV-7
  106.                 Replace........................................ENV-7
  107.                 Again..........................................ENV-7
  108.  
  109.  
  110.  
  111.         Window
  112.                 Size/Move......................................ENV-7
  113.                 Zoom...........................................ENV-8
  114.                 Tile...........................................ENV-8
  115.                 Cascade........................................ENV-8
  116.                 Next...........................................ENV-9
  117.                 Previous.......................................ENV-9
  118.                 Close..........................................ENV-9
  119.         SQL
  120.                 Process........................................ENV-9
  121.                 Form...........................................ENV-10
  122.                 Report.........................................ENV-14
  123.  
  124.          THE EXAMPLE DATABASE .................................DATABASE-1
  125.          USING YOUR OWN WORD PROCESSOR FROM WITHIN SSQLENG.....WORD-1
  126.          USING SCRIPT FILES IN SSQL AND SSQLENG................SCRIPT-1
  127.          PUTTING COMMENTS IN SCRIPT FILES (OR ANY FILE)........SCRIPT-1
  128.          DOS SHELL FROM SSQLENG................................SCRIPT-1
  129.  
  130.          
  131.          EXTRACTING DATA FROM A SINGLE TABLE...................SELECT-1
  132.            Distinct ...........................................SELECT-2
  133.            Where ..............................................SELECT-3
  134.            search_expression ..................................SELECT-3
  135.            Special Search Expression - is null, is not null ...SELECT-5
  136.            Special Search Expression - like, not like .........SELECT-6
  137.            And, Or, Not .......................................SELECT-7
  138.            Any ................................................SELECT-11
  139.            In..................................................SELECT-12
  140.            All.................................................SELECT-12
  141.            Between constant AND constant.......................SELECT-13
  142.            Importance of the NULL (Unknown value)..............SELECT-13
  143.            Mathmatical Functions Avg, Min, Max, Sum, Count.....SELECT-15
  144.            Column Calculations (+, -, *, /) ...................SELECT-18
  145.            Group by, Having ...................................SELECT-19
  146.            Order by ...........................................SELECT-20
  147.            Redirectto .........................................SELECT-21
  148.       
  149.          JOINING...............................................JOIN-1
  150.          SIMPLE SUBQUERIES.....................................SUB-1
  151.          CORRELATED SUBQUERIES.................................COR-1
  152.          CONVERTING ENGLISH TO SQL.............................ENG-1
  153.          CREATE A TABLE........................................CREATE-1
  154.          CREATE A VIEW.........................................VIEW-1
  155.          DROP A TABLE/VIEW.....................................DROP-1
  156.          INSERT DATA INTO A TABLE..............................INSERT-1
  157.          UPDATE DATA IN A TABLE................................UPDATE-1
  158.          DELETE DATA FROM A TABLE..............................DELETE-1
  159.          TUTORIAL..............................................TUTORIAL-1
  160.  
  161.  
  162.  
  163.          
  164.      *** OVERVIEW ***
  165.      SSQL 3.1 is a FULLY-FUNCTIONAL, COMPLETE ANSI SQL implementation
  166.      with the exception of the security features (GRANT, REVOKE).  It
  167.      has everything else:
  168.  
  169.      CREATE                SELECT
  170.          table         any       not exists
  171.          view          all       group by
  172.          index         in        having
  173.      INSERT            like      order by
  174.          values        not       is null
  175.          w/ select     and       is not null
  176.      UPDATE            or        column calculations (+,-,/,*)
  177.      DELETE            exists    aggregate functions 
  178.      DROP                        (avg,min,max,sum, count)
  179.      
  180.      FULL SUPPORT FOR NULLS
  181.      UP TO 14 TABLES IN JOINS
  182.      UP TO 14 LEVELS OF SUBQUERIES
  183.      IT EVEN SUPPORTS CORRELATED SUBQUERIES!!!!!
  184.      
  185.      IT CAN DIRECTLY ACCESS ANY DBASE III-COMPATIBLE FILE (without memo
  186.      fields)
  187.      ALSO, ANY FILE CREATED THROUGH SSQL CAN BE ACCESSED BY A DBASE
  188.      III-COMPATIBLE PROGRAM!!
  189.  
  190.  
  191.      INDEXING THAT MAKES JOINS FASTER THAN DBASE OR ORACLE!!
  192.  
  193.      MANY ADD-ONS THAT MAKE IT EASIER TO WORK WITH:
  194.        Integrated Environment  with full text editor 
  195.        Form Generator (data entry/update/delete/view)
  196.        Report Generator    
  197.        Import/Export text files
  198.        Programmer's interface
  199.      
  200.      
  201.      *** ENHANCEMENTS (PROBLEMS CORRECTED) FROM PREVIOUS VERSIONS ***
  202.      I have been working on this product off-and-on for five years. 
  203.      User feedback has noted some areas that needed of improvement.
  204.      I have addressed the following problems in the current version: 
  205.  
  206.      *1.  SSQL 2.3 IS EXTREMELY USER-UNFRIENDLY.  DIFFICULT TO MAKE
  207.      CORRECTIONS.  DIFFICULT TO SEE, PRINT, AND SAVE RESULTS.
  208.  
  209.      SSQL has a fully-integrated multi-window text editor with full
  210.      mouse-support.  The query is entered in a text window on the left
  211.      half of the screen and the result is in a text window on the right
  212.      half of the screen.  Either window can be easily saved and/or
  213.      printed.
  214.      
  215.      *2.   SSQL 2.3 HAS NO ON-LINE HELP
  216.      Well, now it does.  There is full help for the SSQL environment but only
  217.      the registered users get the full SQL help.
  218.      
  219.  
  220.                                    INTRO-1
  221.  
  222.      *3.  THE MAJOR PROBLEM WITH SSQL 2.2 HAS BEEN THAT IT IS SLOOOOOOW WHEN
  223.      LARGE TABLES ARE JOINED.  
  224.  
  225.      Indexes are now available to increase processing speeds
  226.      dramatically.  Although the shareware version allows you to
  227.      create indexes, only the version with the index option will process
  228.      indexes.  However, the results are dramatic. I did the
  229.      following test on an IBM PC AT using the SSQLENG program directly. 
  230.      Results will be slower using the SSQL environment.
  231.  
  232.                Time In Seconds To Display Various Queries
  233.      
  234.      Number of Rows Joined    SSQLENG   Oracle 5.1    dBase IV 1.1
  235.      
  236.      100 X 100                    5.5           16              38
  237.      100 X 100 X 100             10.0           22              39
  238.      1000 X 1000 10 rows          3.5          123              24
  239.      1000 X 1000 All rows        45.0          157             108
  240.      
  241.      
  242.      
  243.      The dBase results could probably be made better by some
  244.      fine-tuning.  Also, the only version of Oracle available to me is
  245.      an old one.  I hope newer ones are faster.  My current version
  246.      implements only the mostcritical aspects of indexing.  Indexes are
  247.      used when testing for equality and when the tests are linked with
  248.      ANDs.   
  249.  
  250.      Without indexes, (i.e. the shareware version) SSQL would take MANY
  251.      hours to join two tables with 1000 rows each. 
  252.      I got tired trying to find out exactly how long. 
  253.      
  254.  
  255.      *4.  DATA ENTRY IS DIFFICULT AT BEST IN SSQL 2.2.
  256.      
  257.      I have included an easy-to-use program that generates data entry
  258.      screens called FORM.  The screens can be easily
  259.      modified by any text editor.  Besides the basic add, update, view,
  260.      and delete, you can create help screens, cross-
  261.      reference data in another table, test for ranges,  and test for a
  262.      certain set of data.  You can move back and forth from
  263.      entry to entry and there is full data editing capabilities.
  264.  
  265.  
  266.      *5.  REPORT FORMATTING IS PRIMITIVE IN SSQL 2.2.
  267.      
  268.      I have included a report generator that does all the basics -
  269.      subtotals, grand totals, page breaks, page numbering,
  270.      current date, headings, footers, calculations, etc.
  271.      
  272.      
  273.      
  274.  
  275.  
  276.  
  277.  
  278.  
  279.                                    INTRO-2
  280.      *6.  THERE IS NO PROGRAMMING INTERFACE IN SSQL 2.2
  281.  
  282.      Now you can include SSQL in your favorite programming language
  283.      (including batch files).  I have created an extensive command line
  284.      inteface that I use in the SSQL, SSQLFORM and SSQLRPT programs. 
  285.      The interface allows you to access everything that SSQL can do. 
  286.      You can call it from within C (spawn) or even a batch file. 
  287.      Although I haven't tried it, I assume it will work with Pascal and
  288. `    even some dialects of Basic.
  289.  
  290.      I also offer the Turbo C source code for FORM and REPORT to show
  291.      how the calls to SSQL can be integrated into a program.  I admit
  292.      that I am not real proud of the code I produced in version 1.0.  I
  293.      started off with the intention of offering the code so I tried to
  294.      write it in an easy-to-understand style.  Well, as often happens,
  295.      the problem was a bit more involved than I thought and there are a
  296.      few kludges here and there. Oh well, it may give you some ideas!!
  297.      
  298.      No, I do not offer the source code of SSQL.
  299.      
  300.      ** THE COST OF THESE WONDERFUL THINGS **
  301.  
  302.      I have enclosed an order form for your convenience.  It is in the
  303.      file ORDER.FOR. At the DOS prompt type: COPY ORDER.FOR PRN
  304.  
  305.      SSQL 3.1 -                               $35.00
  306.      
  307.      SSQL PRO 3.1 (The version with indexes)  $45.00
  308.  
  309.      SSQL PRO + source code for FORM & REPORT
  310.               + Programmer's Interface        $65.00
  311.  
  312.      Shipping is $3.00 USA (Priority Mail) , $8.00 foreign (airmail)
  313.  
  314.      ***** FOREIGN CUSTOMERS *****
  315.      CHECKS SHOULD BE PAYABLE THROUGH A U.S. BANK.  INTERNATIONAL MONEY
  316.      ORDERS ARE GOOD. SO FAR, I HAVE HAD NO PROBLEM WITH CASH BEING
  317.      SENT THROUGH THE MAIL.  OTHERWISE, USE A CREDIT CARD.
  318.      
  319.      *** THE FUTURE ***
  320.      I have been working on this product for five years with a major
  321.      upgrade at least every year.  Although I refuse to make any
  322.      promises,  this is what I am working on as of July, 1992:
  323.      
  324.  
  325.  
  326.  
  327.                                    INTRO-3
  328.  
  329.      *1.  SQL2.  There is a new SQL specification that is very complex.
  330.      I have tried working on it but I have found that I need help in
  331.      converting the VERY CRIPTIC specifications to algorithms.  One
  332.      person that was going to help me dropped out. If there is anyone
  333.      out there willing to help, I sure would appreciate it.  I need
  334.      someone who can take the specifications and convert it to a set of
  335.      test data along with the various operations and the results based
  336.      on the test data.  I realize it is a monumental task.  The first
  337.      thing I would like to work on is the catalog area because this is
  338.      what users have been requesting.  However, I would accept help in
  339.      any of the many areas in the new specification.  I would also like
  340.      to know if there are any good articles related to SQL2.
  341.  
  342.      *2.  Extensive on-line tutorial with integrated testing.
  343.  
  344.      *3.  Use of expanded memory to allow much larger output tables.
  345.  
  346.      *** THE COMPONENTS OF SSQL ***
  347.  
  348.      There are four components to the SSQL environment.  These four components
  349.      correspond to the four programs:
  350.      SSQL.EXE     - The user-friendly control program
  351.      SSQLENG.EXE  - The SQL engine that does the processing
  352.      SSQLFORM.EXE - A form generator that makes data entry easy
  353.      SSQLRPT.EXE  - A report generator to create formatted reports
  354.      
  355.      * SSQL.EXE *
  356.      This is the main program that you will typically use to enter your SQL
  357.      commands.  Pressing F4 will take the command and send it to SSQLENG.EXE
  358.      for processing and the answer will be displayed in an text window.  You
  359.      can also access the form and report generators.
  360.  
  361.      A complete help system is included, not only for the editor environment,
  362.      but also for SQL syntax and examples.
  363.  
  364.      You enter commands in a full-featured multi-window text editor.  The
  365.      editor uses the older WordStar(tm) style commands and the newer CUA(tm)-
  366.      compatible commands that are popular in Windows 3.0 programs.
  367.  
  368.      * SSQLENG.EXE *
  369.      This is the SQL database engine that does all the work.  This can be run
  370.      as an independent program.  When you run this, you simply type a command
  371.      and get a response. The command can be on multiple lines.
  372.  
  373.      It is useful when you want to avoid the overhead of
  374.      SSQL.EXE which limits the output to about 32,000 characters.  By using
  375.      SSQLENG.EXE directly, the limitation increases 10 times to about 320,000. 
  376.      The input file sizes in either case is unlimited.
  377.  
  378.      There are some non-standard utilities available when using SSQLENG.EXE
  379.      directly. See WORD-1 and SCRIPT-1.
  380.  
  381.      * SSQLFORM.EXE *
  382.      This the very basic forms generator for SSQL.  It allows data entry,
  383.      update, delete, view, and browsing on a row by row basis.  It can be run
  384.      from DOS by typing: SSQLFORM <filename>
  385.      where <filename> is a valid table name.  See details in the SSQLFORM
  386.      section.
  387.  
  388.                                   INTRO-4
  389.  
  390.      * SSQLRPT.EXE *
  391.      This is a basic report generator which can be run by typing:
  392.      SSQLRPT <filename>
  393.      where <filename> is any valid report file.  See details in the REPORT
  394.      section.
  395.  
  396.      *** INSTALLATION AND FINE-TUNING SSQL ***
  397.  
  398.      The following must (normally) reside in the same directory:
  399.      SSQL.EXE
  400.      SSQLENG.EXE
  401.      SSQL.HLP
  402.      SSQLEDIT.HLP
  403.      SSQLENG.ERR
  404.      SSQLFORM.EXE
  405.      SSQLRPT.EXE
  406.      
  407.      You can set a PATH to the directory that contains the above files.
  408.      Your data files must reside in your default directory (the directory you
  409.      are in).  You can also put everything in the same directory.
  410.  
  411.      *** FINE-TUNING ***
  412.  
  413.      When you press F4 to process, SSQL calls the program called SSQLENG.EXE.
  414.      The result of the processing usually is written to QUERY.TXT.
  415.      Control is returned to SSQL and QUERY.TXT is read into an edit screen.
  416.      The speed of this can be greatly enhanced if SSQLENG.EXE is in a RAM
  417.      disk with at least 150K.  Assuming that your RAM disk is D:
  418.      1.   Copy SSQLENG.EXE to D:
  419.      2.   Set the environment variable SSQL to D: with the following command:
  420.           SET SSQL=D:\
  421.      Now when you run SSQL and press F4, SSQL will use D: to load SSQLENG,
  422.      and D: will be used for all temporary files.
  423.      
  424.      *** START UP OPTIONS ***
  425.  
  426.      SSQL /n 
  427.           Opens a new file (the default)
  428.      SSQL *.QRY 
  429.           Goes to Open File and displays all the *.QRY files
  430.      SSQL DEMO.QRY 
  431.           Opens DEMO.QRY in an edit window
  432.      SSQL /w 
  433.           Opens a new file that is as wide as the screen.  It can be used
  434.           with file names and wild cards.
  435.      SSQL /l
  436.           For monochrome LCD screens that do not have highlighting.  It may not
  437.           work on all computers, especially the original (pre-XT) PCs.  You can
  438.           tell it doesn't work by the fact that it locks up.  Use /m which is
  439.           similar.
  440.      SSQL /m
  441.           Regular monochrome displays
  442.  
  443.      SSQL /b
  444.           25-line mode.  This will override the automatic 50-line mode for VGA
  445.           screens.
  446.  
  447.                                   INTRO-5
  448.  
  449.      Any logical combination is OK such as:
  450.      SSQL /m /w *.QRY
  451.      
  452.  
  453.      *** QUICK START ***
  454.      
  455.      At DOS prompt type: SSQL  (and press ENTER)
  456.      Now you are in the SSQL environment.
  457.      Press ENTER at the Intro screen.
  458.      Type the command, e.g.
  459.       select *
  460.       from branch;
  461.  
  462.      Press F4 to process the command.
  463.      
  464.      The answer will appear in a edit window on the right.  You can now edit
  465.      it, print it, save it - anything you can do with a regular file.
  466.      Press F5 to make the query fill the screen.  You can now use the standard
  467.      edit keys to move around the response if it is larger than the screen.
  468.  
  469.      If you want a new query, press ALT-F3 to close the output window on the
  470.      right, otherwise the "desktop" gets cluttered and you will soon run out of
  471.      space.
  472.  
  473.      To erase the previous query quickly, press Shift-PgUp (assuming the cursor
  474.      is at the end of the query), and Ctrl-Del.
  475.  
  476.      The Shift-PgUp marks the entire query, and the Ctrl-Del erases the block.
  477.  
  478.      *** THE BASICS OF THE SSQL ENVIRONMENT ***
  479.  
  480.      When you first type SSQL, and press ENTER the following appears at the
  481.      top:
  482.      File  Edit  Search  Windows SQL
  483.  
  484.      and at the bottom:
  485.      F1 Help  Shift-F1 SQL Help  F3 Open  Alt-F3 Close  F4 Process  F5 Zoom
  486.  
  487.      Since you will usually be using SSQL for entering SQL queries, you will
  488.      probably have little need for the Edit, Search and Windows options. 
  489.      Most of what you need is along the bottom of the screen.  
  490.  
  491.      <F1> Virtually everything that follows is already in over 45 help screens
  492.      that you can access by pressing F1 while in SSQL.
  493.  
  494.      To exit help, press ESC.
  495.  
  496.      Help screens sometimes have highlighted words and phrases which correspond
  497.      to additional help screens.  You can use the TAB key to move to a
  498.      highligted area and press the ENTER key to go to that help screen.
  499.  
  500.      <Shift-F1> will get you SQL help only if you are using the registered
  501.      version.
  502.  
  503.  
  504.  
  505.  
  506.                                    INTRO-6
  507.      <F3> will take you to the File Open screen (see page ).  The default list
  508.      is *.QRY but you can change it to whatever you want.
  509.  
  510.      <ALT-F3> closes a file that is open.  It is important to close a file that
  511.      you are not going to use any more.  Every time you process a query, a
  512.      new file is opened. 
  513.  
  514.      <F4> processes a SQL statement in the active window (the window where
  515.      the cursor is).  If it is a query, the response will appear on the right
  516.      side of the screen. If it is another type of statement such as "create
  517.      table", a message box will appear telling you that the table has been
  518.      created.
  519.  
  520.      <F5> zooms in the active window (makes it fill the screen).  Pressing it
  521.      again makes it shrink back to its original size.  This is especially
  522.      useful if the response to your query is over 40 columns wide.  When the
  523.      response is displayed, press F5 to make it fill the screen.
  524.  
  525.  
  526.      *** DIFFERENCES IN THE REGISTERED VERSION ***
  527.          
  528.      ** PROGRAM
  529.          There is no difference in the registered version except that it has
  530.          full help for SQL syntax.  However, registered users can get a version
  531.         (for an extra $10) that processes indexes.  Indexes can make joins
  532.         (combining data from different files) 40 times or more faster. 
  533.  
  534.      ** DISK-BASED DOCUMENTATION (UNREGISTERED USERS)
  535.          In order to fit everything on a single disk, there is only 
  536.          enough documentation on some commands to explain the basics. 
  537.          However, it does show all the ANSI SQL commands so you can see 
  538.          for yourself that the commands actually work. You do not get 
  539.          documentation on most of the utilities that make working in 
  540.          this environment a bit easier and allow you, for example, to 
  541.          output any query to a dBase file which gives you the ability to 
  542.          customize reports. 
  543.  
  544.      ** FULL DOCUMENTATION (REGISTERED USERS)
  545.  
  546.          Actually, it is much more than just documentation.  There are
  547.          two manuals totaling over 450 pages.  It was produced with a
  548.          desk-top publishing package, printed on a laser printer, and bound.
  549.  
  550.          One manual is APPLYING SQL.  Besides explaining all
  551.          the details of syntax, it shows the common constructs used in 
  552.          SQL to make creating your own queries much easier.  Much of 
  553.          each chapter is centered around translating English into SQL 
  554.          and how to note peculiarities and ambiguities in English that 
  555.          can cause problems in writing queries.
  556.  
  557.          Support is offered through my BBS ((602)945-6181),by mail
  558.          or through CompuServe (73177,2771).
  559.  
  560.  
  561.                               INTRO-7
  562.  
  563.          One of the most complex (and useful) topics in SQL is the 
  564.          correlated subquery.  Most authors give you a page or two on 
  565.          the topic.  That is not nearly enough for you to be able to use 
  566.          it on your own.  My chapter on correlated subqueries is over 40 
  567.          pages.  One good gauge on the quality of a book on SQL is how 
  568.          well it explains the correlated subquery and how well it 
  569.          conveys the importance of the topic.  It is an essential part 
  570.          of SQL that opens up various categories of queries that cannot 
  571.          be accomplished any other way.
  572.          
  573.          The last chapter on queries is CONVERTING ENGLISH TO SQL.  It 
  574.          gives you over 50 pages on approaches to converting English to 
  575.          SQL and dozens of examples.  It explains how to break down a 
  576.          sentence in English that simplifies its conversion.  Many of 
  577.          the common words used in queries are analyzed.  As is often the 
  578.          case with English, the same word in different contexts can 
  579.          significantly change the meaning of the sentence and its 
  580.          conversion to SQL.  Much of the chapter explains how to convert 
  581.          sentences with negation which can be VERY tricky.  For 
  582.          example, let's anylze the following query:
  583.          
  584.          List the purchase dates when all of the following products were 
  585.          purchased: MW, NM, GC. 
  586.          
  587.          The query, although a bit complex when solving it SQL, is 
  588.          nonetheless rather straightforward.  When we negate the query 
  589.          it gets even more confusing (and realistic!!): 
  590.  
  591.          List the purchase dates when all of the following products were 
  592.          NOT purchased: MW, NM, GC. 
  593.          (if all the products were purchased, skip the date) 
  594.  
  595.          List the purchase dates when NONE of the following products were 
  596.          purchased: MW, NM, GC.
  597.          (if any of the products were purchased, skip the date)
  598.  
  599.          List the purchase dates when something other than the following 
  600.          products were purchased: MW, NM, GC. 
  601.  
  602.          Once you see the solutions to these queries you will better 
  603.          understand why SQL is "structured" and it should give you a 
  604.          more critical understanding of English queries.
  605.  
  606.          The full chapters on the joins and subqueries have many more 
  607.          examples and detailed explanations.
  608.  
  609.          The power of SQL can be TOTALLY lost if the user does not 
  610.          understand the basics of data normalization. Normalization 
  611.          involves the rules for creating tables.  If the tables are not 
  612.          organized correctly, SQL cannot be used to its full potential.  
  613.          It is important to note that the topic is discussed with the 
  614.          non-technical end-user in mind.  Since there have not been any 
  615.          widely available SQL programs, all the books on normalization 
  616.          tend to be very theoretical and academically oriented.  
  617.  
  618.  
  619.  
  620.                               INTRO-8
  621.  
  622.          You also get full information on utilities to delete columns from 
  623.          tables, modify column names, change the width of columns, create 
  624.          tables which are subsets of a current table, etc. 
  625.  
  626.          *** PERMISSION TO COPY ***
  627.  
  628.          Please copy this disk and give it to a friend (or anybody else).
  629.          However, the following restrictions apply:
  630.          1.  No changes can be made to the distribution disk, including the 
  631.          documentation.
  632.          2. You cannot copy or reproduce the printed manual.
  633.  
  634.          *** LICENSE AGREEMENT ***
  635.          You are given a 60-day license to use SSQL.  Anything beyond that
  636.          is as illegal and unethical as using any commercial software.
  637.  
  638.          SSQL is shareware, also referred to as user-supported software.
  639.          Try it.  If you like it and use it, register it.  It is well-worth
  640.          the money.  If if doesn't suit your needs, you are not out a lot
  641.          of money.
  642.  
  643.         Shareware is a marketing concept to keep marketing costs down.
  644.         The savings is passed on to the user.   Please help support it.
  645.  
  646.          CLASSROOM USE.  If SSQL is used in a class, each student must be
  647.          a registered user.  Contact SilvaWare for significant volume
  648.          discounts. (HEY! It may be a good time discuss ethics with your
  649.          students!)
  650.  
  651.  
  652.  
  653.  
  654.  
  655.                               INTRO-9
  656.  
  657.  
  658.  
  659.         *** SSQL SPECIFICATIONS ***
  660.  
  661.         Requires only one floppy diskette 
  662.         Minimum Memory 640K,  need 510K usable memory for SSQL if you want to
  663.         use FORM and REPORT
  664.         Maximum number of columns 128
  665.         Maximum length of a row 500 bytes (characters)
  666.         Maximum number of rows 
  667.         It is limited by the overall size of the output.  Under SSQL, the limit
  668.         is about 64K.  If you use SSQLENG directly, the limit is about 320K.
  669.         The tables on the disk can be larger, you just could not display all
  670.         the rows and columns at once.  Also, you could join multiple large
  671.         tables as long as the resultant table was not over 320K. This means
  672.         that the output of a table with rows 100 characters wide could contain
  673.         about 4,000 rows (about 70 pages of report).
  674.         
  675.         Maximum levels of subqueries 14 (reduced by # of indexes in use)
  676.         Maximum number of tables you can join 14 (reduced by # of indexes)
  677.         
  678.         ** CONTENTS OF DISK ***
  679.         READ.ME       - Last minute information
  680.         SSQL.EXE      - The integrated environment
  681.         SSQLENG.EXE   - The database engine
  682.         SSQLFORM.EXE  - The FORM Generator (data entry)
  683.         SSQLRPT.EXE   - The REPORT Generator
  684.         SSQLENG.ERR   - Contains error messages
  685.         EDIT.FIL      - The text file with the location of your word processor
  686.                       - (for use with SSQLENG only!)
  687.         BRANCH.DBF, PROD.DBF, EMP.DBF, MANU.DBF, SALES.DBF, CUST.DBF,
  688.         BRANCH.SQD, PROD.SQD, EMP.SQD, MANU.SQD, SALES.SQD, CUST.SQD,
  689.                       - The tables used in the documentation
  690.         SSQL.DOC      - Documentation
  691.         ORDER.FOR     - Order form. type: COPY ORDER.FOR PRN 
  692.                         for a printout
  693.         PRINTDOC.BAT  - The batch file to print the documentation
  694.         RPT1.FRM TO RPT7.FRM - Report formats for the REPORT program
  695.  
  696.          *** DBASE COMPATIBILITY ***
  697.  
  698.          SSQL creates dBase III compatible files and it can read any 
  699.          dBase file with the following exceptions:
  700.                 No memo data type
  701.                 No field length over 132
  702.  
  703.          A significant difference between SQL and dBase is the ability 
  704.          of SQL to store a null (see SELECT-13 for more information).  
  705.          Even dBase IV cannot store a null.  The way I have done it is 
  706.          that character columns are filled with blanks, and numeric 
  707.          columns contain -0 (negative zero).  You will never see a -0 
  708.          when using SSQL, the column value will be blank.  This 
  709.          information might be useful if you manipulate files created by 
  710.          SSQL in dBase.
  711.  
  712.                               INTRO-10
  713.  
  714.  
  715.          You will notice that every .DBF file created by SSQL has a
  716.          corresponding .SQD file.  This stores information specific to 
  717.          file creation - Not Null and Unique (see CREATE-2 for more 
  718.          information).  If you access a dBase file not 
  719.          created through SSQL, the .DBF file is created with Not Null set 
  720.          for every column and no uniqueness constraints. 
  721.  
  722.          If you change the number of fields in a dBase file after it has 
  723.          been accessed by SSQL, you should delete the corresponding .SQD 
  724.          file. Otherwise, the Not Null and Uniqueness constraints will 
  725.          not be correct.  
  726.  
  727.  
  728.          *** KEY WORDS NEEDED TO UNDERSTAND THE DOCUMENTATION ***
  729.  
  730.          * SQL - Structured Query Language. A standard method of 
  731.          interacting with a database.  It is pronounced "SEQUEL"!!  
  732.          However,  over the years I have noticed more and more people 
  733.          saying the letters S-Q-L.
  734.          
  735.          * TABLE - A table is typically known as a FILE in other systems.
  736.          You may ask why they don't just call a table a file.  It is 
  737.          because that although normally a table does refer to a specific 
  738.          file, a table can refer to something that spans two or more 
  739.          files.  This can be done by "creating a view" (see 
  740.          documentation). If you read a book on relational databases, they 
  741.          will probably refer to a table as a relation. 
  742.  
  743.          * ROW - A row corresponds to a record or a portion of a record in 
  744.          a file.  In relational theory it is called a tuple.
  745.  
  746.          * COLUMN - A column is typically known as a field in other 
  747.          systems.  In relational theory it is called an attribute.
  748.  
  749.          The above names were created to give relational databases a 
  750.          consistent and accurate view of data.
  751.  
  752.          EXAMPLE:
  753.          You may have a TABLE named sales which contains COLUMNs called 
  754.          date, custnum, partnum and quantity.  Every time you made a 
  755.          sale, you would add a ROW of data to the TABLE.
  756.  
  757.                       COLUMNS
  758.            -----------------------------
  759.           |         |        |         |
  760.          date    custnum  partnum  quantity
  761.          ------  -------  -------  --------
  762.          880201  8524     AD873         928       <-- ROW
  763.          880203  7687     VF8709         87       <-- ROW
  764.          ----------------------------------
  765.                         ^
  766.                         |
  767.                       TABLE 
  768.  
  769.  
  770.  
  771.                               INTRO-11
  772.  
  773.  
  774.         *** SYNTAX DIAGRAMS ***
  775.         Many chapters begin with a syntax diagram that concisely
  776.         describes a command and its options.  It takes some practice to
  777.         read them but there are only four basic components:
  778.  
  779.         lowercase_letters - they describe something that you must supply. 
  780.         The rules for correctly writing this part of the command follow
  781.         in the documentation.  It may represent a single word, such as
  782.         the syntax for table_name or a rather complicated series of words
  783.         that is needed for a column_definition.
  784.  
  785.         [  ] - items between square brackets are optional.
  786.  
  787.         ...   -  three dots mean previous item may be repeated.
  788.  
  789.         UPPER CASE LETTERS and all other symbols such as '(', ')', ';',
  790.         '.', and ','  - these must be typed as shown.  Although when
  791.         typing the command, you can use lower case instead of upper case
  792.         letters.  For example, refer to the syntax diagram for creating 
  793.         tables.
  794.         
  795.         Since CREATE TABLE is in uppercase, it must
  796.         always be typed as shown.  The items in lowercase such as
  797.         table_name, column_definition, and uniqueness_constraint must be
  798.         replaced by information you supply.  The rules for forming the
  799.         phrases required by the words in lowercase will be contained in
  800.         the chapter.  The item called column_definition is repeated.  The
  801.         first occurance is outside of the square brackets which means
  802.         that it is required.  The second occurance of column_definition
  803.         is within square brackets which means that it is optional.  There
  804.         is a comma after the left square bracket which means that if you
  805.         add another column_definition, there must be a comma before it. 
  806.         There are three dots after the second occurance of
  807.         column_definition which means that column_definitions can be more
  808.         than two column_definitions.  Other symbols, such as '(', ')' and
  809.         ';' must be included at the positions shown in the example.  In
  810.          SQL, spacing and lines make no difference.  You can create a
  811.         table with all the components on a single line or put each word
  812.         on a separate line.
  813.  
  814.      *** The SilvaWare BBS - LATEST VERSION AND SUPPORT TOO
  815.      *** THE PHONE NUMBER WILL PROBABLY CHANGE IN LATE 1992.  I HAVE BOUGHT
  816.          A NEW HOUSE AND I DO NOT THINK THAT I CAN USE THE SAME NUMBER.
  817.          WRITE ME A NOTE AND I WILL SEND YOU THE NEW NUMBER.
  818.      Currently, it will support 1200/2400 bps but by the end of the year I
  819.      should have support for 9600 and 14400.  The phone number is
  820.      (602) 945-6181. Use the standard settings of 8-N-1.
  821.      The intro screen of my BBS displays the current version of SSQL so you
  822.      don't even have to go to the File section.  If you have a question,
  823.      just leave a message for the sysop.
  824.                          
  825.                               INTRO-12
  826.  
  827.  
  828.      SIGN-ON PROCEDURES
  829.      If you just want to download something, use the name SSQL USER and the
  830.      password is SSQL.
  831.      If you have a question, use your own name when you sign-on and it will
  832.      ask you a few more questions like where you are from and what you want
  833.      your password to be.
  834.  
  835.      TO DOWNLOAD A COPY
  836.      Note the exact name of the file on the intro screen.  Once you have
  837.      gotten through the sign-on procedures:
  838.      Press F to get to the FILES section
  839.      Press D to download the file
  840.      Type in the name of the file and press ENTER
  841.      (It will ask for another name - just press ENTER)
  842.  
  843.      What you do next is up to your communications package.  I assume that
  844.      you know something about uploading and downloading.  If you don't,
  845.      practice on a local BBS first.  The first file you need to download is
  846.      PKUNZIP because all files on my BBS (and most others) are "ZIPPED"
  847.      to organize files, save space, and save time in downloading.
  848.           I hope to make my BBS a meeting place for people interested in SQL.
  849.      If you have any interesting information about SQL, feel free to upload
  850.      it.
  851.  
  852.      *** SQLBBS - ANOTHER PLACE TO GET THE LATEST VERSION ***
  853.           The SQLBBS is a BBS in the Chicago area. It is free to everyone.  You
  854.      can download whatever you want on the first call.  It even allows you to
  855.      use Oracle (the most popular SQL DBMS) on-line.  The BBS phone number is:
  856.      (312) 589-0508
  857.      Currently supported baud rates are 9600/2400/1200/300
  858.      The following is the fastest way to find and download the most current
  859.      version of SSQL.  It assumes that you are somewhat familiar with BBSs.
  860.  
  861.      My comment are in the blocks surrounded by asterisks, the other information
  862.      is what you see on the screen.
  863.      **********************************************************************
  864.      * WHEN YOU FIRST LOG-IN TO THE BBS YOU WILL SEE THE FOLLOWING MAIN   *
  865.      * MENU.  PRESS 'F' TO GET TO THE FILE MENU                           *
  866.      **********************************************************************
  867.                   ------*>>>   RBBS-PC  MAIN MENU   <<<*------
  868.      ----- MAIL ---------- SYSTEM ---------- UTILITIES ------ ELSEWHERE ---
  869.       [E]nter Messages  [*]nswer Questions [H]elp (or ?)       [D]oors
  870.       [K]ill Messages   [B]ulletins        [*]oin Conferences  [F]iles
  871.       [P]ersonal Mail   [C]omment to Sysop [*]iew Conf. Mail   [G]oodbye
  872.       [R]ead Messages   [I]nitial Welcome  [X]pert on/off      [Q]uit
  873.       [S]can Messages   [O]perator Page                        [U]tilities
  874.       [T]opic of Msgs   [*]ho's on          * = unavailable    [*]Library
  875.      ----------------------------------------------------------------------
  876.        Current time: 07:54 AM  Minutes remaining: 42     Security: 5
  877.      ----------------------------------------------------------------------
  878.      MAIN command <?,B,C,D,E,F,H,I,K,O,P,Q,R,S,T,U,X>! F
  879.  
  880.  
  881.  
  882.  
  883.                               INTRO-13
  884.  
  885.  
  886.      **********************************************************************
  887.      * AFTER PRESSING 'F', YOU WILL BE AT THE FILE MENU.                  *
  888.      * PRESS 'S' TO SEARCH FOR A FILE                                     *
  889.      **********************************************************************
  890.  
  891.            ------*>>>   RBBS-PC  FILE MENU   <<<*------
  892.      -- TRANSFER ------ INFORMATION --- UTILITIES --- ELSEWHERE -
  893.       [D]ownload file   [L]ist files   [H]elp (or ?)   [G]oodbye
  894.       [*]ersonal dwnld  [N]ew files    [X]pert on/off  [Q]uit
  895.       [U]pload file     [S]earch files
  896.                         [V]iew archives      * = unavailable
  897.      ------------------------------------------------------------
  898.            Current time: 07:54 AM     Minutes remaining: 42
  899.      ------------------------------------------------------------
  900.  
  901.      FILE command <?,D,G,H,L,N,Q,S,U,V,X>! S
  902.  
  903.      **********************************************************************
  904.      * WHEN IT ASKS WHAT TO SEARCH FOR, TYPE                              *
  905.      * SSQL                                                               *
  906.      * IMPORTANT!!!! MAKE SURE THAT SSQL IS IN UPPER-CASE!!!!!            *
  907.      **********************************************************************
  908.  
  909.      Search for (in file name/desc, wildcards name only, [ENTER] quits)? SSQL
  910.  
  911.      **********************************************************************
  912.      * THEN IT WILL ASK YOU WHICH DIRECTORIES                             *
  913.      * PRESS 'A' FOR ALL DIRECTORIES                                      *
  914.      **********************************************************************
  915.  
  916.      * Ctrl-K(^K) / ^X aborts. ^S suspends ^Q resumes *
  917.      UPLD
  918.      DOWNLD
  919.      What directory(s) (U)pload,A)ll,L)ist,E)xtended +/-, [Q]uit)? A
  920.      Scanning Directory DOWNLD for SSQL
  921.  
  922.      **********************************************************************
  923.      THE FOLLOWING LINE WILL GIVE YOU THE CURRENT VERSION.                *
  924.      IF IT IS HIGHER THAN SSQL31, YOU MAY WANT TO DOWNLOAD IT.            *
  925.      **********************************************************************
  926.  
  927.      SSQL31   ZIP   (THE REST IS DATE AND SIZE INFORMATION)
  928.      End list.  R)elist, [Q]uit, or download what?
  929.  
  930.      **********************************************************************
  931.      * IF YOU WANT TO DOWNLOAD IT, JUST TYPE THE NAME OF THE FILE         *
  932.      * (IN THIS CASE SSQL31.ZIP), AND FOLLOW THE INSTRUCTIONS             *
  933.      **********************************************************************
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.                               INTRO-14
  941.  
  942.  
  943.  
  944.      *** UNIX VERSION NOW AVAILABLE ***
  945.  
  946.      I have ported the SSQLENG portion of the package to SCO Unix.  SSQLENG
  947.      is the SQL engine and can be used directly from DOS.  See INTRO-4,
  948.      WORD-1, and SCRIPT-1 for details.  It works exactly the way it does in
  949.      DOS.  It handles multi-user problems correctly too.  If it is run with
  950.      tables that are read-only, you can use the SELECT statement, but
  951.      INSERT, UPDATE, and DELETE will return an error message.  You can only
  952.      use CREATE in directories where you have access, otherwise it will
  953.      give you an error message.
  954.  
  955.      You can get the shareware version for free by accessing the SSQL BBS
  956.      and downloading it from the SCO Unix file area.  You can also send me
  957.      $10 and I will send it to you on a 3 1/2" or 5 1/4" DOS disk.
  958.  
  959.      DIFFERENCES BETWEEN THE SHAREWARE VERSION AND THE REGISTERED VERSION
  960.      1. The shareware version has an obnoxious intro screen that begs for
  961.      money.
  962.      2. The shareware version comes with a 60-day license.  Naturally, there
  963.      is no limit on the registered version.
  964.      3. The registered version allows the use of indexing which speeds up
  965.      joins and subqueries many, many times.
  966.      4. The registered version has on-line help.
  967.      5. You get a bound, laser-printed manual of over 400 pages which is
  968.      virtually the same as the one you get with a DOS registration.
  969.      6. Registered users can purchase extra copies of the manual for $15.
  970.  
  971.      COST OF THE REGISTERED VERSION FOR SCO UNIX
  972.      Only $100 per CPU plus $3 shipping in U.S., or $8 foreign (airmail).
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.  
  995.  
  996.  
  997.                               INTRO-15
  998.  
  999.  
  1000.  
  1001.      *** THE TEXT EDITOR ***
  1002.  
  1003.  
  1004.      The commands for the file editor are standard to most editors.
  1005.      You can use the ancient WordStar(tm) commands, or the more modern
  1006.      CUA(tm) commands used on products such as Borland languages and
  1007.      WordPerfect for Windows.  Actually it is not 100% CUA but it comes close. 
  1008.      Some CUA cominations will not work on the original (pre-XT) PCs and
  1009.      compatibles.
  1010.  
  1011.      ** Block Commands 
  1012.      
  1013.      * Mark A Block 
  1014.      Move the cursor to one end of the block.  While holding down the shift key
  1015.      use the arrow keys to move to the other end of the block.  Now it is
  1016.      marked.
  1017.       Or...
  1018.       Begin mark Ctrl-K B
  1019.       End mark   Ctrl-K K
  1020.       Mark word  Ctrl K T
  1021.      Once a block is marked, you can use the following:
  1022.       Copy    Ctrl-K C  
  1023.       Move    Ctrl-K V 
  1024.       Delete  Ctrl-K Y or Ctrl-Del
  1025.  
  1026.      Or you can use the edit commands:
  1027.       Ctrl-Ins   Copy block to clipboard
  1028.       Shift-Del  Cut block and put in clipboard
  1029.       Shift-Ins  Paste block from clipboard
  1030.      
  1031.  
  1032.       ** Cursor Movement Commands 
  1033.                                                       
  1034.        Character left  |  Left arrow or Ctrl-S
  1035.        Character right |  Right arrow or Ctrl-D
  1036.        Word left       |  Ctrl-Left arrow or Ctrl-A
  1037.        Word right      |  Ctrl-Right arrow or Ctrl-F
  1038.        Line up         |  Up arrow or Ctrl-E
  1039.        Line down       |  Down arrow or Ctrl-X
  1040.        Page up         |  PgUp or Ctrl-R
  1041.        Page down       |  PgDn or Ctrl-C
  1042.                   
  1043.  
  1044.        ** Insert & Delete Commands
  1045.  
  1046.        Insert mode on/off     | Ins or Ctrl-V
  1047.        Delete line            | Ctrl-Y
  1048.        Delete to end of line  | Ctrl-Q Y
  1049.        Delete character left  | Backspace or Ctrl-H
  1050.        Delete character       | Del or Ctrl-G
  1051.        Delete word right      | Ctrl-T
  1052.      
  1053.                                          ENV-1
  1054.  
  1055.  
  1056.  
  1057.  
  1058.       * Miscellaneous Editor Commands
  1059.  
  1060.        Menu bar                 | F10
  1061.        Save and Edit            | F2
  1062.        New File                 | F3
  1063.        Close Active Window      | ALT-F3
  1064.        Find                     | Ctrl-Q F
  1065.        Find and Replace         | Ctrl-Q A
  1066.        Repeat last Find/Replace | Ctrl-L
  1067.        Cancel Operation         | Esc
  1068.  
  1069.      ** File  (Alt-F) 
  1070.  
  1071.      The File menu offers choices for opening files, changing
  1072.      directories, and exiting the program.
  1073.  
  1074.      * File-Open  (F3) 
  1075.  
  1076.      The Open command displays the Open a File dialog box. In this dialog box
  1077.      you select the text file you want edit.
  1078.  
  1079.      The Open a File dialog box contains:
  1080.       The File Dialog Box 
  1081.  
  1082.      The File dialog box contains an input box, a file list,
  1083.      a file information panel, the standard button Cancel,
  1084.      one other action button (Open if you selected File
  1085.      Open or OK if you selected Save As...), plus a history
  1086.      list that's attached to the Name Input Box.
  1087.       Name Input Box
  1088.       ⁄ƒ Name ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒø
  1089.       ≥                                 ≥
  1090.       ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ
  1091.      The Name input box is where you enter the name of the file to load,
  1092.      or the file-name mask to use as a filter for the Files list box
  1093.      (for example, *.QRY).
  1094.  
  1095.                                          ENV-2
  1096.  
  1097.  
  1098.  
  1099.       ⁄ Files ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒø
  1100.       ≥                                 ≥
  1101.       ≥  FILENM01.QRY  ≥  FILENM09.QRY  ≥
  1102.       ≥  FILENM02.QRY  ≥  FILENM10.QRY  ≥
  1103.       ≥  FILENM03.QRY  ≥  FILENM11.QRY  ≥
  1104.       ≥  FILENM04.QRY  ≥  FILENM12.QRY  ≥
  1105.       ≥  FILENM05.QRY  ≥  ..            ≥
  1106.       ≥  FILENM06.QRY  ≥  \MOREXAMP     ≥
  1107.       ≥  FILENM07.QRY  ≥  \TOURS        ≥
  1108.       ≥  FILENM08.QRY  ≥  \ANSWERS.DIR  ≥
  1109.       ≥  ±±±˛±±±±±±±±±±±±±±±±±±±±±±   ≥
  1110.       ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ
  1111.      The Files list box lists the names of files in the current
  1112.      directory that match the file-name mask in the Name input box,
  1113.      plus the parent directory and all subdirectories.
  1114.  
  1115.       ⁄ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒø
  1116.       ≥ C:\TP\EXAMPLES\*.QRY                     ≥
  1117.       ≥ HELLO.QRY       52  Jul 14,1990  12:00pm ≥
  1118.       ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ
  1119.      The File information panel shows the path name, file name, date, time,
  1120.      and size of the selected file.
  1121.  
  1122.      None of the items on this information panel are selectable. 
  1123.       ⁄ƒƒƒƒƒƒƒƒƒƒø
  1124.       ≥ [ Open ] ≥
  1125.       ¿ƒƒƒƒƒƒƒƒƒƒŸ
  1126.      The Open button opens a new Edit window and places the selected file in
  1127.      that window.
  1128.  
  1129.       ⁄ƒƒƒƒƒƒƒƒƒƒƒƒø
  1130.       ≥ [ Cancel ] ≥
  1131.       ¿ƒƒƒƒƒƒƒƒƒƒƒƒŸ
  1132.  
  1133.      If you choose Cancel, nothing changes and no action occurs, and the
  1134.      dialog box is put away.
  1135.  
  1136.      (Esc always cancels a dialog box, even if a Cancel button does not
  1137.      appear.)
  1138.      
  1139.      * File-New
  1140.  
  1141.      File New opens up a edit box to start entering new information.
  1142.      When you exit, it will ask whether you want to save it to a file.
  1143.  
  1144.      * File-Save  (F2)
  1145.  
  1146.      Save the current file.  If it is untitled (you selected
  1147.      File-New), you will be asked for a name.
  1148.  
  1149.                                          ENV-3
  1150.  
  1151.  
  1152.  
  1153.      * File-Save As... 
  1154.  
  1155.      Use the Save As... selection when you want to name an untitled file
  1156.      (you selected File|New), or you want to save a file under a different
  1157.      name.
  1158.      The original file will be left unchanged.
  1159.      The  command displays the Save a File dialog box. In this dialog box you
  1160.      can select the file name you want to save it under or enter a new name.
  1161.  
  1162.      For a description of the dialog box, see File Open above.
  1163.  
  1164.      * File-Change Dir...
  1165.  
  1166.      File-Change Dir brings up the Change Directory
  1167.      dialog box, in which you can change the current directory.
  1168.  
  1169.      The Change Directory dialog box consists of an input box, a list box,
  1170.      the standard OK and Help buttons, and two other buttons (Chdir and
  1171.      Revert).
  1172.  
  1173.       ⁄ Directory Name ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒø
  1174.       ≥                                     ≥
  1175.       ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ
  1176.      The Directory Name input box is where you type in the path of the new
  1177.      directory.
  1178.  
  1179.       ⁄ Directory Tree ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒø
  1180.       ≥   Drives                            ≥
  1181.       ≥   ¿ƒ¬C:\                            ≥
  1182.       ≥     ¿ƒ¬SSQL                         ≥
  1183.       ≥       ¿ƒƒTABLES                     ≥
  1184.       ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ
  1185.  
  1186.                                     ENV-4
  1187.  
  1188.  
  1189.  
  1190.      The Directory Tree list box enables you to navigate directories by using
  1191.      the selecting bar and pressing Enter.
  1192.  
  1193.      If you're using the keyboard, press Enter to make the selected directory
  1194.      be the current directory, then choose OK or press Esc to exit the dialog
  1195.      box.
  1196.  
  1197.       ⁄ƒƒƒƒƒƒƒƒƒƒø
  1198.       ≥ [Chdir ] ≥
  1199.       ¿ƒƒƒƒƒƒƒƒƒƒŸ
  1200.      The Chdir button changes the current directory once you've
  1201.      selected or typed in a directory name.
  1202.  
  1203.       ⁄ƒƒƒƒƒƒƒƒƒƒø
  1204.       ≥ [Revert] ≥
  1205.       ¿ƒƒƒƒƒƒƒƒƒƒŸ
  1206.      The Revert button goes back to the previous directory, as long as you
  1207.      haven't yet exited the dialog box.
  1208.  
  1209.      * File-Print
  1210.  
  1211.      Prints whatever is in the current window and then advances to the top of
  1212.      the next page.
  1213.  
  1214.      * File-DOS Shell
  1215.  
  1216.      With the DOS Shell command, you can leave the program temporarily to
  1217.      perform a DOS command or run another program.
  1218.  
  1219.      To return to this program, type EXIT at the DOS prompt.
  1220.  
  1221.      * File-Exit    (Alt-X)
  1222.  
  1223.      The Exit command terminates this program.
  1224.  
  1225.      ** Edit (ALT-E)
  1226.  
  1227.      The Edit menu conatins commands to undo the previous edit
  1228.      operation, cut a block of text and put it in the
  1229.      clipboard, copy a block of text into the clipboard,
  1230.      paste the most recent block put in the clipboard, show
  1231.      the clipboard which contains ALL previous blocks put
  1232.      in the clipboard, and clear which clears the block from
  1233.      the screen and does not put it in the clipboard.
  1234.  
  1235.      * Edit-Undo
  1236.  
  1237.      The Undo command takes back the last editing command you
  1238.      performed on a line.
  1239.  
  1240.                                     ENV-5
  1241.  
  1242.  
  1243.  
  1244.      * Edit-Cut (Shift-Del)
  1245.  
  1246.      The Cut command removes the blocked text form your document and puts the
  1247.      text in the clipboard.
  1248.  
  1249.      You can then move to another location in your document and choose paste
  1250.      to take the cut text out of the clipboard and put it in your document.
  1251.  
  1252.      The text stays in your clipboard so you can paste it more than once.
  1253.  
  1254.  
  1255.      * Edit-Copy (Ctrl-Ins) 
  1256.  
  1257.      The Copy command leaves the selected text intact and places a copy of it
  1258.      in the clipboard.
  1259.  
  1260.      You can then move to another location in your document and choose paste
  1261.      to take the cut text out of the clipboard and put it in your document.
  1262.  
  1263.      The text stays in your clipboard so you can paste it more than once.
  1264.  
  1265.      * Edit-Paste (Shift-Ins)
  1266.  
  1267.      The paste command copies the selected text from the clipboard into the
  1268.      document at the cursor.
  1269.  
  1270.      * Edit-Show Clipboard
  1271.  
  1272.      The Show Clipboard command opens the clipboard window which stores the
  1273.      text you cut and copied from other windows.
  1274.  
  1275.      The currently selected (highlighted) text is the text SSQL uses when
  1276.      you choose paste:.
  1277.  
  1278.      * Edit-Clear (Ctrl-Del)
  1279.  
  1280.      The clear command removes the selected text but does not put it into the
  1281.      clipboard.
  1282.  
  1283.      The cleared text is retrievable with the undo command.
  1284.  
  1285.      ** Search
  1286.  
  1287.      The Search menu contains command to find text in the current file, replace
  1288.      existing text with new text, and search again for text to find or replace.
  1289.  
  1290.                                     ENV-6
  1291.  
  1292.  
  1293.  
  1294.      * Search-Find (Ctrl-Q F) 
  1295.  
  1296.      The find command displays a dialog box where you enter the text that you
  1297.      want to find.  It starts searching where the cursor is to the bottom of
  1298.      the file.  If you want to search for the same text again, press Ctrl-L
  1299.      or select Search Again
  1300.  
  1301.      * Search-Replace (Ctrl-Q A)
  1302.  
  1303.      The Replace command combines the Find command with the ability to replace
  1304.      the text it finds with new text.  You will be asked to enter the text
  1305.      to find.  Remember to press the Tab to get to the entry for the
  1306.      replacement text.  Use the SearchAgain option to find and replace the next
  1307.      occurence of text.
  1308.  
  1309.      * Search-Again (Ctrl-L)
  1310.  
  1311.      The Search Again command repeats the last Find or Replace.
  1312.  
  1313.      ** Window  (Alt-W)
  1314.  
  1315.      The Window menu contains commands to close, move and perform other
  1316.      window-management commands.
  1317.  
  1318.      Most of the windows in this program have all the standard window
  1319.      elements, including scroll bars, a close box, and zoom icons. 
  1320.      For more about windows and their elements, refer to windows. 
  1321.  
  1322.      * Window-Size/Move (Ctrl-F5)
  1323.  
  1324.      Choose this command to change the size or position of the active window.
  1325.  
  1326.  
  1327.      * Size
  1328.  
  1329.      If you press Shift while you use the arrow keys, you can change the size
  1330.      of the active window. Once you've adjusted its size or position, press
  1331.      Enter.
  1332.  
  1333.      If a window has a Resize corner, you can drag that corner to resize the
  1334.      window.
  1335.  
  1336.  
  1337.      * Move
  1338.      
  1339.      When you choose Window≥Size/Move, the active window moves in response to
  1340.      the arrow keys. Once you've moved the window to where you want it, press
  1341.      Enter.
  1342.  
  1343.                                     ENV-7
  1344.  
  1345.  
  1346.  
  1347.      You can also move a window by dragging its title bar with the mouse.
  1348.  
  1349.      * Window-Zoom (F5)
  1350.      
  1351.      Choose Zoom to resize the active window to the maximum size. If the
  1352.      window is already zoomed, you can choose this command to restore it to
  1353.      its previous size.
  1354.  
  1355.      You can also double-click anywhere on the window's title bar (except
  1356.      where an icon appears) to zoom or unzoom the window. 
  1357.  
  1358.      * Window-Tile
  1359.  
  1360.      Choose Window-Tile to tile all file viewers on the desktop.
  1361.  
  1362.       ⁄ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒø
  1363.       ≥ …ÕÕÕÕÕÕÕÕÕÕÕÕ1ÕÕª⁄ƒƒƒƒƒƒƒƒƒƒƒƒ2ƒƒø ≥
  1364.       ≥ ∫               ∫≥               ≥ ≥
  1365.       ≥ ∫               ∫≥               ≥ ≥
  1366.       ≥ ∫               ∫≥               ≥ ≥
  1367.       ≥ ∫               ∫≥               ≥ ≥
  1368.       ≥ »ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ ≥
  1369.       ≥ ⁄ƒƒƒƒƒƒƒƒƒƒƒƒ3ƒƒø⁄ƒƒƒƒƒƒƒƒƒƒƒƒ4ƒƒø ≥
  1370.       ≥ ≥               ≥≥               ≥ ≥
  1371.       ≥ ≥               ≥≥               ≥ ≥
  1372.       ≥ ≥               ≥≥               ≥ ≥
  1373.       ≥ ≥               ≥≥               ≥ ≥
  1374.       ≥ ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ ≥
  1375.       ¿ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒŸ
  1376.                   Tiled Windows
  1377.  
  1378.      * Window-Cascade 
  1379.  
  1380.      Choose Window-Cascade to stack all file viewers on the desktop. 
  1381.       ⁄ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ1ƒø
  1382.       ≥⁄ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ2ƒø
  1383.       ≥≥⁄ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒ3ƒø
  1384.       ≥≥≥…ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕ4Õª
  1385.       ≥≥≥∫                         ∫
  1386.       ≥≥≥∫                         ∫
  1387.       ≥≥≥∫                         ∫
  1388.       ≥≥≥∫                         ∫
  1389.       ≥≥≥∫                         ∫
  1390.       ¿¿¿»ÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕÕº
  1391.              Cascaded Windows
  1392.  
  1393.  
  1394.                                     ENV-8
  1395.  
  1396.  
  1397.      * WindowNext 
  1398.  
  1399.      Choose Next to cycle forwards through the windows on the desktop. 
  1400.  
  1401.      * Window-Previous
  1402.  
  1403.      Choose Previous to cycle backwards through the windows on the desktop.
  1404.  
  1405.      * Window-Close  (Alt-F3)
  1406.  
  1407.      Choose Close to close the active window.
  1408.  
  1409.      You can also click the Close box in the upper right corner to close a
  1410.      window.
  1411.  
  1412.  
  1413.      ** SQL
  1414.  
  1415.      * File-Process (F4)
  1416.  
  1417.      The Process command takes the text that is displayed and sends it to the
  1418.      SSQL engine to be processed.  If it is a query, the response will be in a
  1419.      text file called QUERY.TXT that is opened to the right of the query.
  1420.      Other commands will have a response in a box to describe what occurred.
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.  
  1434.  
  1435.  
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441.  
  1442.  
  1443.  
  1444.  
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.  
  1454.                                     ENV-9
  1455.  
  1456.          
  1457.          
  1458.      *** FORM ***
  1459.          The Form program allows you to insert, update, view and delete 
  1460.          in a much more user-friendly environment than standard SQL 
  1461.          offers.  It will generate a standard form for a table that can 
  1462.          then be modified - or you can start from scratch.  Each column 
  1463.          in the table can have a: 
  1464.               Help screen
  1465.               Column validation - it exists in another table
  1466.               Column validation - it is within a particular range
  1467.               Column validation - it is within a set of values
  1468.          
  1469.          With the column validation, if a mistake is made, the correct 
  1470.          values are displayed on the screen. 
  1471.          
  1472.          You have full data editing capabilities and you can easily move 
  1473.          from prompt to prompt to make changes.  You can even change the 
  1474.          colors. 
  1475.          
  1476.          You can retrieve rows of information from the form based on 
  1477.          simple search criteria and then page through the rows 
  1478.          retrieved. 
  1479.          
  1480.          The current version is limited to tables with less than 24 
  1481.          rows. 
  1482.          
  1483.          However, as an incentive for you to register, only the basics 
  1484.          are given to you.  The order form is on the last page of the 
  1485.          SSQL documentation or you can just print ORDER.FRM. 
  1486.          
  1487.          
  1488.          * SUMMARY OF KEYS WITHIN THE FORM *
  1489.  
  1490.          UP/DOWN ARROWS will move you from prompt to prompt.
  1491.  
  1492.          LEFT/RIGHT ARROWS will move you within the prompt as long as 
  1493.          there is text. 
  1494.  
  1495.          HOME KEY will take you to the beginning of the text.
  1496.  
  1497.          END KEY will take you to the end of the text.
  1498.  
  1499.          INSERT KEY will switch between the insert mode and the 
  1500.          overwrite mode. 
  1501.  
  1502.          DELETE KEY will delete the character where the cursor is at. 
  1503.  
  1504.          PAGEUP (used in Update/View mode) will display the previous row 
  1505.          of information. 
  1506.  
  1507.          PAGEDOWN (used in Update/View mode) will display the next row 
  1508.          of information. 
  1509.  
  1510.  
  1511.                                     ENV-10
  1512.  
  1513.  
  1514.          ESC will cancel the entry and exit the form program.
  1515.  
  1516.          ENTER will move you from prompt to prompt.  At the last prompt, 
  1517.          it will accept the form and insert the information into the 
  1518.          table. 
  1519.          
  1520.          F1   When help has been defined for the form, a window containing 
  1521.               the help message will be displayed.
  1522.          
  1523.          F2   Takes the information you have already entered in the form and
  1524.               searches the table for a match.  All rows that match are
  1525.               retrieved.  You can use the PAGEUP/PAGEDOWN to display the
  1526.               other rows.
  1527.          
  1528.          F4   Displays the column value entered in the previous row.  This
  1529.               is useful when, for example, you need to enter the same city
  1530.               over and over.  Type the city once.  For the next row of
  1531.               information, just press the F4 when you get to the city
  1532.               column.
  1533.          
  1534.          ALT-I     Puts you in INSERT mode.
  1535.          ALT-V     Puts you in VIEW mode and turns off column validation.
  1536.          ALT-U     UPDATEs what is on the screen.
  1537.          ALT-D     DELETEs based on what is on the screen.
  1538.          
  1539.          
  1540.          * GENERATING A FORM *
  1541.          In order to more easily explain the commands in the form, let's
  1542.          start by having the form program generate a form for us.  To do
  1543.          that:
  1544.          1.   Make sure that the form program is accessable from the
  1545.               directory with your table files.  We will be using the CUST
  1546.               table that is on the SSQL distribution disk.
  1547.          2.   Type: form cust (and press ENTER)
  1548.          
  1549.          The form program generates a file called CUST.SCR which 
  1550.          describes the form and then runs the form and puts you in the 
  1551.          insert mode. Press ESC to exit the form. 
  1552.          
  1553.          Now you have a file on your disk called CUST.SCR which looks 
  1554.          like: 
  1555.          
  1556.          D1 Data Entry for CUST
  1557.          D1 CODE   ~~
  1558.          D1 NAME   ~~~~~~~~~~~~~~~
  1559.          D1 ST     ~~
  1560.          D1 RATING ~~
  1561.          CO CODE
  1562.          CO NAME
  1563.          CO ST
  1564.          CO RATING
  1565.          TA CUST
  1566.          
  1567.          The first two columns on every line must contain a command.  The
  1568.          commands are:
  1569.  
  1570.                                     ENV-11
  1571.  
  1572.  
  1573.          D1   This displays information on the screen.  Anything you type
  1574.               will appear on the screen EXCEPT the underline.  The ~ (til)
  1575.               shows where data entry will occur.  Every ~ must have
  1576.               a corresponding CO line which defines the column.  The first
  1577.               ~s will be matched with the first CO line, the second
  1578.               ~s will be matched with the second CO line, and so on.
  1579.               The ~s do not have to be as wide as the column is
  1580.               defined.  If, for example, the column is defined as being 80
  1581.               characters, you can have ~s only 30 characters wide.
  1582.               It will create a text window.  Although you can only see 30
  1583.               characters at a time, you can still enter the full 80
  1584.               characters.
  1585.          
  1586.          CO   A single valid column name in the table must follow the CO
  1587.               command.  There must be a CO command for every set of ~s that
  1588.               appears in the D1 commands.
  1589.          
  1590.          TA   The table name is put here.
  1591.          
  1592.          As for the ordering of the commands, the only thing to remember 
  1593.          is that the CO command must follow the corresponding ~s.
  1594.          We could rewrite the cust screen to be any of the following: 
  1595.          
  1596.          TA CUST
  1597.          D1 Data Entry for CUST
  1598.          D1 CODE   ~~
  1599.          CO CODE
  1600.          D1 NAME   ~~~~~~~~~~~~~~~
  1601.          CO NAME
  1602.          D1 ST     ~~
  1603.          CO ST
  1604.          D1 RATING ~~
  1605.          CO RATING
  1606.          
  1607.          D1******************************************************
  1608.          D1*              CUSTOMER FORM                         *
  1609.          D1* Customer Number  ~~  Company Name  ~~~~~~~~~~~~~~~ *
  1610.          D1* State ~~ Rating ~~                                 *
  1611.          D1******************************************************
  1612.          CO CODE
  1613.          CO NAME
  1614.          CO ST
  1615.          CO RATING
  1616.          TA CUST
  1617.          
  1618.          (The following reverses ST and RATING to show that you do not have
  1619.          to put the columns in the same order as they exist in the table.)
  1620.  
  1621.                                     ENV-12
  1622.  
  1623.  
  1624.          D1******************************************************
  1625.          D1*              CUSTOMER FORM                         *
  1626.          D1* Customer Number  ~~  Company Name  ~~~~~~~~~~~~~~~ *
  1627.          D1* Rating ~~  State ~~                                *
  1628.          D1******************************************************
  1629.          CO CODE
  1630.          CO NAME
  1631.          CO RATING
  1632.          CO ST
  1633.          TA CUST
  1634.          
  1635.          
  1636.          *** INSERT ***
  1637.          You are in the insert mode when you start the form.  Refer to 
  1638.          the SPECIAL KEYS section for your options within the form.  For 
  1639.          a NULL, press the ENTER key without entering anything for the 
  1640.          column. Pressing the ENTER key at the last prompt will insert 
  1641.          the row into the table. 
  1642.          
  1643.          *** UPDATE ***
  1644.          NOTE: The Update will only work on tables where the Unique 
  1645.          constraint has been specified.  By using the Unique on one or 
  1646.          more columns when the table is created, it determines the key 
  1647.          for the table.  For more information, see the Create Table 
  1648.          instructions in SSQL.DOC. There are three basic steps to 
  1649.          updating: 
  1650.          1.   Press ALT-V to get into the VIEW mode.  
  1651.          2.   Retrieve the row you want to update.  You retrieve rows by 
  1652.               entering data in one or more prompts on the form and pressing
  1653.               F2.  It will retrieve all rows that are equal to the data you
  1654.               entered.  For example, you want to change the rating on a
  1655.               customer in Arizona, but you forget the exact name.  You could
  1656.               move to the ST prompt, type AZ, and press F2.  The first
  1657.               customer in AZ would be displayed. You could then use PgUp and
  1658.               PgDn to find the correct customer.
  1659.          3.   Change the data in any of the prompts.  If more than one row
  1660.               was retrieved, you can press PageDn to move to the next row. 
  1661.               When you have changed the row you want updated, Press Alt-U.
  1662.          
  1663.          *** VIEW ***
  1664.          The only difference between update and view is that in view, no
  1665.          data is changed.
  1666.          1.   Press ALT-V to get into the view mode.  
  1667.          2.   Retrieve the row(s) you want to view.  You retrieve rows by
  1668.               entering data in one or more prompts on the form and pressing
  1669.               F2.  It will retrieve all rows that are equal to the data you
  1670.               entered.  For example, if you wanted to view all the customers
  1671.               in Arizona, you would move to the ST prompt, type AZ, and
  1672.               press F2.  The first customer in AZ would be displayed.  
  1673.          3.   If more than one row was retrieved, you can press PageDn to
  1674.               move to the next row - then PageUp move back a row.
  1675.          
  1676.          *** DELETE ***
  1677.          To delete a row, you follow the steps for updating except at step
  1678.          3 you press ALT-D to delete the row being displayed.
  1679.  
  1680.                                     ENV-13
  1681.  
  1682.  
  1683.          ***REPORT Version 1.0 - The SSQL Report Generator ***
  1684.  
  1685.  
  1686.          *** OVERVIEW ***
  1687.          SSQL Report allows you to produce a formatted report.  You use 
  1688.          SSQL (or any text editor).  Instead of just reading the 
  1689.          documentation, it is a good idea to first study and run the 
  1690.          examples and then come back to the documentation.  As is common 
  1691.          with shareware documentation, you need to register in order to 
  1692.          find out all the details of operation. 
  1693.          
  1694.          *** PROCESS A REPORT ***
  1695.          To process a report, first make sure that SSQL has been installed   
  1696.  
  1697.          properly.  The tables you reference MUST be in the current
  1698.          directory. Select The Report Option from SQL Menu in SSQL by 
  1699.          pressing ALT-Q and then R.
  1700.          A file menu will be displayed with the .FRM files which contain the
  1701.          report files.  The files RPT1.FRM to RPT7.FRM have been included on 
  1702.          the distribution disk.  Make sure that RPT1.FRM is in your 
  1703.          current directory along with the DBF/SQD files.  Select RPT1.FRM
  1704.          and the result will be displayed on the screen after a few moments  
  1705.          (quite a few moments if you are using a floppy disk).
  1706.          It can also be run directly from DOS by typing: SSQLRPT RPT1.FRM
  1707.  
  1708.          
  1709.          ***SYNTAX OF REPORT FILES***
  1710.          All lines begin with a command.  All commands are two 
  1711.          characters long.  The first character after the command 
  1712.          corresponds to column one on the report. The following example 
  1713.          shows you a basic report. 
  1714.  
  1715.          -- RPT1.FRM (With 3 tables and no indexing, it is slow on an
  1716.          --           old PC)
  1717.          HT                      SALES REPORT
  1718.          HT
  1719.          HT      DATE      CUST NAME        PROD DESCRIP     QTY
  1720.          HT      ********  ***************  ***************  ***
  1721.          DT      XXXXXXXX  XXXXXXXXXXXXXXX  XXXXXXXXXXXXXXX  999
  1722.          ET**** END OF REPORT ****
  1723.          DC date, name, descrip, qty
  1724.          TA sales,cust,prod
  1725.          WH cc = cust.code and
  1726.          WH pc = prod.code
  1727.          
  1728.          ** COMMENTS (--) 
  1729.          Begin a line with two dashes if you do not want it processed by 
  1730.          the program. 
  1731.          
  1732.          ** PRINTER (PR)
  1733.          If you want the report sent to the printer, the command is PR, 
  1734.          and the number after it refers to the printer number.  If you 
  1735.          do not know the printer number, it is probably 1.  
  1736.          
  1737.                                    ENV-14
  1738.          
  1739.          It advances to the next page after 59 lines.  I made it 59 
  1740.          instead of 66 for those of us with Laserjets. If you do not have 
  1741.          the PR command, the report will be displayed on the screen. 
  1742.          
  1743.          ** HEADING (HT) (optional)
  1744.          The heading is produced at the top of every page or screen.    
  1745.          Headings can contain text, the current date (in both U.S. and 
  1746.          international formats), a page number, and you can skip a pre-
  1747.          determined number of lines (good for setting margins).  For 
  1748.          information on HOW to do all this, register and get the full 
  1749.          documentation. 
  1750.          
  1751.          ** DETAIL TEXT(DT)
  1752.          The detail represents the placement of information for each row 
  1753.          retrieved from the table.  The information can be placed on 
  1754.          more than one line.  It corresponds to the rows requested in 
  1755.          the Detail Columns (DC) line. It may contain text, but Xs and 
  1756.          9s have special meaning. 
  1757.          
  1758.          X
  1759.          This is used for character data.  It will only display the 
  1760.          number of characters represented by the number of Xs you have 
  1761.          for the column.  This is useful when a column may be defined as 
  1762.          having 30 columns but you just want to see the first 15.  You 
  1763.          would simply put only 15 Xs in the position you wanted the 
  1764.          column information to be displayed. 
  1765.          
  1766.          9
  1767.          The 9 represents numeric data.  You need to make sure that you 
  1768.          have enough 9s for the largest number in the column, otherwise 
  1769.          asterisks (*) will be displayed instead.  Numeric data can be 
  1770.          specially formatted (more on that in the full documentation). 
  1771.          
  1772.          ** FOOTER (FT) (optional)
  1773.          The footer is placed at the bottom of every page sent to the 
  1774.          printer.  It is skipped over if the report is sent to the 
  1775.          screen.  The options for the footer are the same as the ones 
  1776.          for the heading. 
  1777.          
  1778.          ** END OF REPORT (ET) (optional)
  1779.          This information appears just once, at the end of the report.  
  1780.          The options are that same as the ones for the heading. 
  1781.          
  1782.          ** DETAIL COLUMNS (DC)
  1783.          There must be a column for every format described under DT.  
  1784.          The format follows the syntax for the select statement in SSQL.  
  1785.          This means that you can have calculated columns, aggregate 
  1786.          functions - anything that you can put between the word SELECT 
  1787.          and the word FROM in a select statement.  There can be only one 
  1788.          DC line. 
  1789.          
  1790.          ** SUBTOTALS (optional) **
  1791.          Actually, subtotal is a misnomer because you can use any 
  1792.          aggregate function (count, avg, min, max, sum) - not just sum.  
  1793.          There are three parts to creating subtotals.  The first part is 
  1794.          the format (1T) which has the same rules as the ones for detail 
  1795.          
  1796.                                    ENV-15
  1797.          
  1798.  
  1799.          text (DT).  The second part determines the group you want 
  1800.          subtotaled (1B).  The third part (1C) contains the aggregate 
  1801.          function(s) that you want in the subtotal.  The command sent to 
  1802.          SSQL is: 
  1803.          SELECT Break Column(s), Subtotals 
  1804.          FROM   (TA line) 
  1805.          WHERE  (WH line(s)) GROUP BY Break Column(s); 
  1806.          
  1807.          For example:
  1808.          
  1809.          --RPT2.FRM
  1810.          HT SALES REPORT
  1811.          HTCust  Prod  QTY 
  1812.          HT----  ----  ---
  1813.          DTXX    XX    999
  1814.          1T           ----
  1815.          1T Cust Tot  9999
  1816.          1T
  1817.          DC cc, pc, qty
  1818.          1B cc
  1819.          1C sum(qty)
  1820.          TA sales
  1821.          
  1822.          ** SUBTOTAL TEXT (1T)
  1823.          This is where you describe the format of the subtotal.  The 
  1824.          rules are the same as the ones for detail text (DT) except that 
  1825.          you can only use numeric data (9s). 
  1826.          
  1827.          ** BREAK COLUMN(S) (1B)
  1828.          This refers to the column(s) that you want the aggregate 
  1829.          functions grouped by.  The column(s) must also exist in the 
  1830.          Detail Columns (DT).  It functions just like the GROUP BY 
  1831.          clause.  See the manual under the section GROUP BY in chapter 
  1832.          10 for more information on what can be put here. 
  1833.          
  1834.          ** SUBTOTALS (1C)
  1835.          This is where you put the aggregate functions that you want 
  1836.          displayed in the format you described in the Subtotal Text 
  1837.          (1T).  You need one aggregate function for every numeric format 
  1838.          in 1T. 
  1839.          
  1840.          ** GRAND TOTAL (optional)
  1841.          Again a misnomer.  You can do more than total a column (sum), 
  1842.          you can use any aggregate function.  The grand total is 
  1843.          displayed once at the end of the report.  There are two parts: 
  1844.          grand total text (GT) describes the format, and grand total 
  1845.          columns (GC) describes the aggregate function that you want 
  1846.          displayed.  The command sent to SSQL is: 
  1847.          SELECT Grand Total Column(s) 
  1848.          FROM   (TA line) 
  1849.          WHERE  (WH line(s)) 
  1850.          
  1851.  
  1852.  
  1853.  
  1854.          
  1855.                                    ENV-16
  1856.          
  1857.  
  1858.          For example:
  1859.          
  1860.          --RPT3.FRM
  1861.          HT SALES REPORT
  1862.          HTCust  Prod  QTY 
  1863.          HT----  ----  ---
  1864.          DTXX    XX    999
  1865.          GT           ----
  1866.          GT Grand Tot 9999
  1867.          DC cc, pc, qty
  1868.          GC sum(qty)
  1869.          TA sales
  1870.          
  1871.          
  1872.          ** GRAND TOTAL TEXT (GT)
  1873.          This is where you describe the format of the grand total.  The 
  1874.          rules are the same as the ones for detail text (DT) except that 
  1875.          you can only use numeric data (9s). 
  1876.          
  1877.          ** GRAND TOTAL COLUMN(S) (GC)
  1878.          List the aggregate function(s) that you want in the grand 
  1879.          total.  There must be one aggregate function for every numeric 
  1880.          format described in GT. 
  1881.          
  1882.          
  1883.          ** TABLE(S) (TA)
  1884.          This correponds to one or more tables that you want selected.  
  1885.          There can be only on TA line in a report.  Anything valid after 
  1886.          the first FROM in SQL is valid here.  See the manual in chapter 
  1887.          10 and 11 for more information on what can be put here. 
  1888.          
  1889.          ** THE WHERE CLAUSE (WH) (optional)
  1890.          Anything valid after the first FROM in SQL is valid here 
  1891.          including subqueries with the following exception:  You cannot 
  1892.          have a GROUP BY or an ORDER BY if you have also specified 
  1893.          subtotals.  Make sure that the DC, TA, and WH lines go together 
  1894.          to form a valid statement as in: 
  1895.          SELECT (DC line) 
  1896.          FROM   (TA line) 
  1897.          WHERE  (WH line(s)); 
  1898.          
  1899.          
  1900.                                    ENV-17
  1901.          
  1902.  
  1903.          Some more extensive report formats and hints.
  1904.          
  1905.          --RPT4.FRM (Be patient when running this one.  It actually 
  1906.          --          contains three queries)
  1907.          --
  1908.          HT        SALES REPORT
  1909.          HT    MONOLITH MANUFACTURING 
  1910.          HTCustomer Name    Product     QTY 
  1911.          HT---------------  ----------  ---
  1912.          DTXXXXXXXXXXXXXXX  XXXXXXXXXX  999
  1913.          1T                          ------
  1914.          1T The customer total is    99,999
  1915.          1T
  1916.          GT                         -------
  1917.          GT GRAND TOTAL ............999,999
  1918.          ET
  1919.          ET^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1920.          ET                 END OF REPORT
  1921.          ET^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1922.          DC name, descrip, qty
  1923.          1B name
  1924.          1C sum(qty)
  1925.          GC sum(qty)
  1926.          TA sales,prod,cust
  1927.          WH sales.cc = cust.code and
  1928.          WH sales.pc = prod.code
  1929.          
  1930.          
  1931.          --RPT4A.FRM - another way of writing RPT4.FRM
  1932.          HT        SALES REPORT
  1933.          HT    MONOLITH MANUFACTURING 
  1934.          HTCustomer Name    Product     QTY 
  1935.          HT---------------  ----------  ---
  1936.          DTXXXXXXXXXXXXXXX  XXXXXXXXXX  999
  1937.          DC name, descrip, qty
  1938.          1T                          ------
  1939.          1T The customer total is    99,999
  1940.          1T
  1941.          1B name
  1942.          1C sum(qty)
  1943.          GT                         -------
  1944.          GT GRAND TOTAL ............999,999
  1945.          GC sum(qty)
  1946.          ET
  1947.          ET^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1948.          ET        END OF REPORT
  1949.          ET^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1950.          TA sales,prod,cust
  1951.          WH sales.cc = cust.code and
  1952.          WH sales.pc = prod.code
  1953.  
  1954.  
  1955.  
  1956.  
  1957.  
  1958.          
  1959.                                    ENV-18
  1960.          
  1961.  
  1962.          --RPT5.FRM - Multiple line detail
  1963.          HT                      SALES REPORT
  1964.          HT
  1965.          HT      DATE      CUST CODE        PROD CODE        QTY
  1966.          HT                CUST NAME        PROD DESCRIP     
  1967.          HT      ********  ***************  ***************  ***
  1968.          DT      XXXXXXXX  XX               XX               999
  1969.          DT                XXXXXXXXXXXXXXX  XXXXXXXXXXXXXXX
  1970.          DT
  1971.          DC date, cc, pc, qty, name, descrip
  1972.          TA sales,cust,prod
  1973.          WH cc = cust.code and
  1974.          WH pc = prod.code
  1975.          
  1976.          
  1977.          --RPT6.FRM - Projections
  1978.          -- Minor quirk - when you repeat column names as in the DC line
  1979.          -- below, "rename" them by putting a unique identifier after each
  1980.          -- one.
  1981.          HT          THE EFFECT OF A PERCENTAGE INCREASE 
  1982.          HT                 IN PERCENT OF DEFECTS
  1983.          HT
  1984.          HT                MANU   PROD     ** DEFECTS **
  1985.          HT      DATE      STATE  CODE     0% 10% 20% 30% 
  1986.          HT      --------  --     --      --  --  --  --   
  1987.          DT      XXXXXXXX  XX     XX      99  99  99  99 
  1988.          DC date,mst,code,defects,defects*1.1 d2,defects*1.2 d3,defects*1.3 d4
  1989.          TA prod
  1990.          
  1991.          --RPT7.FRM Multiple subtotals
  1992.          -- Minor quirk - when you repeat column names as in the 1C line
  1993.          -- below, "rename" them by putting a unique identifier after each
  1994.          -- one.
  1995.          HT      Code Defects Qty
  1996.          DT      XX   99      99
  1997.          1T      Average      99
  1998.          1T      Total        99
  1999.          1T      Maximum      99
  2000.          1T      Minimum      99
  2001.          DC code, defects,qty
  2002.          TA prod
  2003.          1B code
  2004.          1C avg(defects), sum(defects) c2, max(defects) c3, min(defects) c4
  2005.          
  2006.  
  2007.   
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.                                    ENV-19
  2019.  
  2020.          *** THE EXAMPLE DATABASE - MONOLITH MANUFACTURING ***
  2021.          Monolith Manufacturing manufactures and markets high tech
  2022.          products in the western states.  There are manufacturing
  2023.          facilities in various states.  Products are manufactured in
  2024.          batches at each facility.  When the batch is finished an entry is
  2025.          made in the table with the date the batch was finished, the
  2026.          product code, the state where the product was manufactured, the
  2027.          quantity of saleable items and the percent of defects in the
  2028.          batch if that is tracked.  Related to the manufacturing table is
  2029.          the product table which simply has the description that
  2030.          corresponds to each product code.
  2031.          The sales portion of the business has as its core the sales
  2032.          table.  When a sale is made, an entry is made which contains the
  2033.          date of sale, branch code, customer code, salesperson number,
  2034.          product code and quantity purchased.  Related to the sales table
  2035.          are the branch table, the employee table and the customer table. 
  2036.          The branch table contains the branch code, the state the branch
  2037.          is in and the employee number of the manager.  The employee table
  2038.          contains the employee number, the name of the employee, and the
  2039.          employee's manager number if the employee has a manager (the
  2040.          president does not have a manager).  All manager numbers have an
  2041.          entry in the employee number column since all managers are also
  2042.          employees.  The customer table contains the customer code, the
  2043.          customer name and the state where the customer resides.
  2044.          The following contains details on the Monolith's six tables.  The
  2045.          data types correspond to the types used in the create table
  2046.          command.  When a column in one table corresponds to a column
  2047.          (especially a primary key) in another table, it is in the form of
  2048.          TABLE.column. This information will be useful when we need to
  2049.          retrieve information that spans tables. 
  2050.          
  2051.          SALES TABLE
  2052.          column  data                               Common columns in 
  2053.          name    type       description             other tables
  2054.          date    date       Date of sale 
  2055.          bc      char(2)    Branch code             BRANCH.code
  2056.          cc      char(2)    Customer code           CUST.code
  2057.          sn      numeric(2) Salesperson number      EMP.code,
  2058.                                                  EMP.mgrnum, BRANCH.mgrnum
  2059.          pc      char(2)    product code            PROD.code, MANU.code
  2060.          qty     numeric(3) quantity
  2061.  
  2062.          Key is date, bc, cc, sn, pc
  2063.  
  2064.  
  2065.  
  2066.          
  2067.          
  2068.          
  2069.          
  2070.          
  2071.  
  2072.          
  2073.                                DATABASE-1
  2074.  
  2075.  
  2076.  
  2077.  
  2078.          BRANCH TABLE
  2079.          column   data                              Common columns in 
  2080.          name     type       description            other tables
  2081.          code     char(2)    branch code            SALES.bc
  2082.          st       char(2)    state code             CUST.st, MANU.mst
  2083.          mgrnum   numeric(2) manager number         EMP.enum,
  2084.                                                     EMP.mgrnum, SALES.sn
  2085.          KEY is code
  2086.          
  2087.          EMP TABLE
  2088.          column   data                              Common columns in 
  2089.          name     type       description            other tables
  2090.          enum     numeric(2) employee number        EMP.mgrnum, BRANCH.mgrnum, 
  2091.                                                     SALES.sn 
  2092.          name     char(20)   employee name
  2093.          mgrnum   numeric(2) manager number         EMP.enum,
  2094.                                                     BRANCH.mgrnum, SALES.sn
  2095.          KEY is enum
  2096.  
  2097.          PROD TABLE
  2098.          column   data                              Common columns in 
  2099.          name     type       description            other tables
  2100.          code     char(2)    product code           MANU.code, SALES.pc
  2101.          descrip  char(15)   product description
  2102.          KEY is code        
  2103.  
  2104.          MANU TABLE
  2105.          column   data                               Common columns in 
  2106.          name     type       description             other tables
  2107.          date     date       date of manufacture
  2108.          code     char(2)    product code            PROD.code
  2109.          mst      char(2)    state where product     BRANCH.st, PROD.st
  2110.                              is manufactured
  2111.          defects  numeric(3) percent defects in batch  
  2112.          qty      numeric(3) quantity manufactured
  2113.          KEY is date, code, ms
  2114.  
  2115.          CUST TABLE
  2116.          column   data                               Common columns in 
  2117.          name     type       description             other tables
  2118.          code     char(2)    Unique customer code    SALES.cc
  2119.          name     char(15)
  2120.          st       char(2)    State                   MANU.mst, PROD.st
  2121.          rating   numeric(2)  
  2122.          KEY is code
  2123.          
  2124.          
  2125.  
  2126.  
  2127.  
  2128.  
  2129.  
  2130.  
  2131.          
  2132.                                DATABASE-2
  2133.  
  2134.          
  2135.          
  2136.          
  2137.          USING YOUR WORD PROCESSOR
  2138.  
  2139.          You can modify any SSQL command by calling your text editor or
  2140.          word processor from within SSQL.  You must first specify which
  2141.          text editor or word processor you are using in a file called
  2142.          EDIT.FIL.  The file must contain the path and name of the text
  2143.          editor or word processor.  YOU CANNOT CALL A BATCH FILE.  The
  2144.          distribution disk contains an EDIT.FIL with the following:
  2145.          C:\PCWRITE\ED
  2146.          The command to start PC-Write is ED and it resides on drive C: in
  2147.          the PCWRITE directory.  You can replace the above line with the
  2148.          path and program name of your own. The EDIT.FIL must reside on
  2149.          your default directory. The syntax is:
  2150.          EDIT [file_name];
  2151.          The file_name is any valid name which will be accepted by your
  2152.          word processor on the command line.  For example, if you want to
  2153.          edit MGRORG, you would type:
  2154.          edit mgrorg;
  2155.          As is true with all commands except calling a script file, you
  2156.          must end this one with a ';'.  When you exit your word
  2157.          processor/text editor, you will return to SSQL.  Refer to the
  2158.          next section to find out how to process the file you just
  2159.          created.
  2160.          There is a special case when you want to edit the last SSQL
  2161.          command that you typed.  Every command you type except edit and
  2162.          exit is stored in a file called RUN.  To edit the last command
  2163.          entered type:
  2164.          edit run;
  2165.          If your word processor does not allow you to type the file name
  2166.          that you want to edit after the word processor command in
  2167.          EDIT.FIL simply type:
  2168.          edit;
  2169.  
  2170.  
  2171.  
  2172.  
  2173.  
  2174.  
  2175.  
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181.  
  2182.  
  2183.  
  2184.  
  2185.  
  2186.  
  2187.  
  2188.  
  2189.  
  2190.          
  2191.                                    WORD-1
  2192.  
  2193.          
  2194.          
  2195.          
  2196.          CALL SCRIPT FILE 
  2197.  
  2198.          A script file is a text file which contains an SSQL command.  The
  2199.          script file can then be called from SSQL or SSQLENG and the command it
  2200.          contains will be processed.
  2201.          
  2202.          SYNTAX:
  2203.          @file_name 
  2204.          
  2205.          The file_name can be any valid DOS file name.
  2206.          The file must be text only, no special word processing formats
  2207.          allowed. PC-Write or Qedit are excellent choices because they
  2208.          always produce standard text. 
  2209.          
  2210.          COMMENTS IN THE SCRIPT FILE (OR ANY OTHER FILE)
  2211.          You can precede a comment by two dashes and from that point to
  2212.          the end of the line will not be processed by SSQL. The comment
  2213.          can be at any place in the line, not necessarily at the beginning
  2214.          as the following example shows.
  2215.          You can create a file called MGRORG which contains:
  2216.          --This query finds the names of managers who have
  2217.          -- salespeople who have sold products to Organomice
  2218.          select name      --Get names
  2219.          from emp      
  2220.          where enum in 
  2221.            (select mgrn   --of managers
  2222.             from emp 
  2223.             where enum in   
  2224.               (select sn        -- who have salespeople
  2225.                from sales,cust  -- who have sold products to
  2226.                where cc = code  -- Organomice
  2227.                and name = 'Organomice')); 
  2228.          
  2229.          From SSQL or SSQLENG, you would simply type:
  2230.          @MGRORG 
  2231.  
  2232.          Or, from SSQL, use F3 to open MGRORG, and then press F4 to process it.
  2233.  
  2234.          If you do this from SSQLENG, the file you created would be displayed
  2235.          on the screen and then the result would appear.
  2236.  
  2237.          The script file can contain multiple commands.
  2238.          
  2239.          DOS COMMANDS FROM SSQLENG
  2240.          From within SSQLENG, you can type DOS, press ENTER and be in a DOS
  2241.          shell.  You can then type EXIT and return to SSQLENG.  You can take
  2242.          a short-cut and, for example call Qedit from within SSQLENG to edit
  2243.          MGRORG with the command from within SSQLENG:
  2244.          DOS Q MGRORG
  2245.          At this point you will be in Qedit and be able to edit your query.
  2246.          When you exit Qedit, you will be in SSQLENG and be able to call
  2247.          the script file MGRORG.
  2248.  
  2249.  
  2250.                             SCRIPT-1
  2251.  
  2252.  
  2253.          QUERIES - SINGLE TABLE
  2254.  
  2255.          OVERVIEW
  2256.  
  2257.          The select command is used to retrieve data from tables. The
  2258.          select command is covered in three later chapters too.  Although
  2259.          the use of select on a single table is relatively easy,
  2260.          translating from English to SQL (or most other query languages)
  2261.          can be rather tricky.  The approach of this chapter is not merely
  2262.          to explain the syntax of the command, it should give you a more
  2263.          critical approach to applying SQL.
  2264.  
  2265.          SYNTAX: 
  2266.  
  2267.          SELECT [DISTINCT] column_name [,column_name ...] 
  2268.          FROM table_name [,table_name ...] 
  2269.          [WHERE search_expression] 
  2270.          [REDIRECTTO file_name]         <--Non-Standard 
  2271.          [GROUP BY column_name [,column_name ...] 
  2272.          [HAVING criteria]]
  2273.          [ORDER BY column_name [,column_name ...] 
  2274.  
  2275.          If you want all the columns in a table you can replace the list
  2276.          of column names with an asterisk (*). 
  2277.          The select command produces a report in the form of a table.
  2278.          Although the basic use of the select takes a short time to learn,
  2279.          the more advanced uses take a long time to master. 
  2280.          The tables used in this chapter are on the distribution disk so
  2281.          you can try entering the commands yourself.
  2282.          All the examples have each clause starting on a new line for
  2283.          purposes of clarity. It is not necessary to have them on separate
  2284.          lines. It is sometimes advantageous to keep the query on one line
  2285.          because if you need to make a correction, you cannot backup a
  2286.          line. However, to make correcting command much easier, you can
  2287.          call your word processor from within SSQL. This is described in
  2288.          the full documentation.
  2289.  
  2290.          THE BASICS OF SELECT 
  2291.  
  2292.          Find all the data in the manu table.
  2293.          
  2294.          select *  
  2295.          from manu; 
  2296.          date     code mst defects qty  
  2297.          -------- ---- --- ------- ---  
  2298.          02/07/87 GC   ID       12  15 
  2299.          02/01/87 GC   ID        0  55  
  2300.          02/02/87 NM   CA       17  93  
  2301.          02/02/87 DD   ID           25  
  2302.          02/03/87 DD   WA       22  46  
  2303.          02/02/87 NM   WA       15  25  
  2304.          02/04/87 DD   AZ       12  25  
  2305.          02/04/87 DD   CA       15  25  
  2306.          02/06/87 GC   AZ        4  43  
  2307.           
  2308.  
  2309.                                 SELECT-1
  2310.  
  2311.          
  2312.          Instead of typing all the column names, you can use the * to
  2313.          denote all column names. On the next line, the "from manu" tells
  2314.          us that we want the data to come from the table named "manu". All
  2315.          select commands must end with a semi-colon (;). If we just wanted
  2316.          the product code and the state that it was manufactured in you
  2317.          would type:
  2318.          
  2319.           select code, mst 
  2320.           from manu; 
  2321.           code mst  
  2322.           ---- ---  
  2323.           GC   ID   
  2324.           GC   ID   
  2325.           NM   CA   
  2326.           DD   ID   
  2327.           DD   WA   
  2328.           NM   WA   
  2329.           DD   AZ   
  2330.           DD   CA   
  2331.           GC   AZ   
  2332.            
  2333.           9 rows selected 
  2334.          
  2335.          DISTINCT 
  2336.          The optional statement "distinct" will eliminate all rows with
  2337.          duplicate columns that you have specified. If you wanted to find
  2338.          out all the different states where products are manufactured, you
  2339.          would type:
  2340.          
  2341.          select distinct mst 
  2342.          from manu; 
  2343.           
  2344.          mst  
  2345.          ---  
  2346.          ID   
  2347.          CA   
  2348.          WA   
  2349.          AZ   
  2350.           
  2351.          4 rows selected 
  2352.          
  2353.          As you can see only 4 rows were found. This is because  there can
  2354.          be more than one row with the same state. Only the first
  2355.          occurrence of each data element is retained. 
  2356.          The "distinct" modifier can be used with one or more column names
  2357.          in a select statement. However, the "distinct" modifier operates
  2358.          on the whole row, not just a single column. In the manu table,
  2359.          the primary key is date, code, mst. What if we wanted not only
  2360.          the state where the products are manufactured but the product
  2361.          codes too. Notice what happens with the following:
  2362.  
  2363.  
  2364.  
  2365.  
  2366.          
  2367.          
  2368.                                 SELECT-2
  2369.  
  2370.          
  2371.          select mst, code 
  2372.          from manu; 
  2373.           
  2374.          mst code  
  2375.          --- ----  
  2376.          ID  GC    
  2377.          ID  GC    
  2378.          CA  NM    
  2379.          ID  DD    
  2380.          WA  DD    
  2381.          WA  NM    
  2382.          AZ  DD    
  2383.          CA  DD    
  2384.          AZ  GC    
  2385.          
  2386.          Some of the rows are duplicated because it is possible to
  2387.          manufacture the same product in the same state but on a different
  2388.          date. To get rid of the duplication of rows we can add the
  2389.          "distinct" modifier.
  2390.          
  2391.          WHERE 
  2392.          
  2393.          The where clause of the select command is the most powerful and
  2394.          complex part of SQL. Our discussion will be broken down into
  2395.          various phases. The first phase is using the where with a single
  2396.          table name. Later you will see it used with multiple tables and
  2397.          you will find that you can even put another select command within
  2398.          the where clause. 
  2399.          
  2400.          search_expression 
  2401.          
  2402.          The simplest search expression relates a column name to a
  2403.          constant. A constant is an exact value that you enter. All column
  2404.          values are tested against the constant value. If the column name
  2405.          that you are testing is defined as a character, the constant must
  2406.          be enclosed in single quotes or double quotes. The constant you
  2407.          are searching for may not contain a quote. If the column name you
  2408.          are testing for is defined as numeric, the constant is a number
  2409.          without any quotes. 
  2410.          You can relate the column name to the constant in the following
  2411.          ways: 
  2412.          
  2413.          = equal 
  2414.          <> not equal 
  2415.          != not equal 
  2416.          ~= not equal
  2417.          >  greater than 
  2418.            less than 
  2419.          >= greater than or equal 
  2420.          <=  less than or equal 
  2421.          IS NULL   column value is null
  2422.          IS NOT NULL   column value is not null
  2423.          LIKE  like a pattern
  2424.          NOT LIKE  not like a pattern
  2425.  
  2426.  
  2427.                                 SELECT-3
  2428.  
  2429.  
  2430.  
  2431.          
  2432.          Find out which customers are in Arizona. 
  2433.          
  2434.          select * 
  2435.          from cust 
  2436.          where st = 'AZ'; 
  2437.           
  2438.          code name            st rating  
  2439.          ---- --------------- -- ------  
  2440.          ZZ   Organomice      AZ     34  
  2441.          DD   QuarkCo         AZ     10  
  2442.           
  2443.          2 rows selected 
  2444.          
  2445.          Spaces are optional on either side of the "=". You could have
  2446.          typed: 
  2447.          
  2448.          where st='AZ'; 
  2449.          
  2450.          Instead of single quotes you could have used double quotes: 
  2451.          
  2452.          where st="AZ"; 
  2453.          
  2454.          In the manu table, the column name "defects" is the percent of
  2455.          defects when the product was manufactured. The statement below
  2456.          shows you how to get a list of all the information for those
  2457.          products with defects over 10%.
  2458.          
  2459.          select * 
  2460.          from manu 
  2461.          where defects > 10; 
  2462.           
  2463.          date     code mst defects qty  
  2464.          -------- ---- --- ------- ---  
  2465.          02/07/87 GC   ID       12  15  
  2466.          02/02/87 NM   CA       17  93  
  2467.          02/03/87 DD   WA       22  46  
  2468.          02/02/87 NM   WA       15  25  
  2469.          02/04/87 DD   AZ       12  25  
  2470.          02/04/87 DD   CA       15  25  
  2471.           
  2472.          6 rows selected 
  2473.          
  2474.          The symbols such as <, >, =, <=, >=, and != can be used with
  2475.          character data too. For example, the statement below shows how to
  2476.          retrieve all customer names alphabetically greater than Machado.
  2477.  
  2478.  
  2479.  
  2480.  
  2481.  
  2482.  
  2483.  
  2484.  
  2485.          
  2486.                                 SELECT-4
  2487.  
  2488.  
  2489.  
  2490.  
  2491.  
  2492.          
  2493.          select name 
  2494.          from cust 
  2495.          where name > "Machado"; 
  2496.           
  2497.          name             
  2498.          ---------------  
  2499.          Technoharps      
  2500.          Organomice       
  2501.          QuarkCo          
  2502.          Marswarp         
  2503.          Multicrud        
  2504.           
  2505.          5 rows selected 
  2506.          
  2507.          SPECIAL SEARCH EXPRESSION - IS NULL, IS NOT NULL 
  2508.          
  2509.          Nulls are an important concept in relational databases. For
  2510.          example, let's look at the percentage of defects in Idaho:
  2511.          
  2512.          select *
  2513.          from manu
  2514.          where mst = 'ID'; 
  2515.            
  2516.          date     code mst defects qty  
  2517.          ------   ---- --- ------- ---  
  2518.          02/07/87 GC   ID       12  15  
  2519.          02/01/87 GC   ID        0  55  
  2520.          02/02/87 DD   ID           25  
  2521.           
  2522.          3 rows selected 
  2523.           
  2524.          In Idaho, the batch of MW on 02/07/87 has 12% defects, GC on 02/01/87
  2525.          has 0% defects but there is nothing listed for DD. This "nothing"
  2526.          is called a null. It does not mean zero or blank. A null means
  2527.          that the data element is unknown. In our case, product DD in
  2528.          Idaho is not tracked for defects like other products. This isn't
  2529.          to say that there are zero defects. It just means we have no
  2530.          entry. 
  2531.          If we wanted to look at all products for which we do not track
  2532.          defects, we would use the following:
  2533.          
  2534.          select * 
  2535.          from manu 
  2536.          where defects is null; 
  2537.          date     code mst defects qty  
  2538.          -------- ---- --- ------- ---  
  2539.          02/02/87 DD   ID           25  
  2540.           
  2541.          1 row selected 
  2542.          
  2543.  
  2544.  
  2545.                                 SELECT-5
  2546.  
  2547.  
  2548.          
  2549.          We could find all the products for which we track defects by
  2550.          using is not null:
  2551.          
  2552.          select * 
  2553.          from manu 
  2554.          where defects is not null; 
  2555.          date     code mst defects qty  
  2556.          -------- ---- --- ------- ---  
  2557.          02/07/87 GC   ID       12  15  
  2558.          02/01/87 GC   ID        0  55  
  2559.          02/02/87 NM   CA       17  93  
  2560.          02/03/87 DD   WA       22  46  
  2561.          02/02/87 NM   WA       15  25  
  2562.          02/04/87 DD   AZ       12  25  
  2563.          02/04/87 DD   CA       15  25  
  2564.          02/06/87 GC   AZ        4  43  
  2565.           
  2566.          8 rows selected 
  2567.          
  2568.          Null values can be used with both numeric columns and character
  2569.          columns.
  2570.          
  2571.          SPECIAL SEARCH EXPRESSION - LIKE, NOT LIKE 
  2572.          
  2573.          An expression with like is used when we want to retrieve data
  2574.          that is similar in some way to another set of characters. The
  2575.          like expression can only be used with character data. This is
  2576.          explained in the full documentation.
  2577.          
  2578.          AND, OR, NOT 
  2579.          
  2580.          We can link expressions with ands and ors. If you use an and,
  2581.          both expressions have to be true in order to add the row to the
  2582.          table we are producing. If you use an or, only one of the
  2583.          expressions has to be true. You can use as many ands and ors as
  2584.          you want in a query. The expressions are evaluated from left to
  2585.          right. All the ands are done first, then evaluation starts again
  2586.          from the left and the ors are processed. 
  2587.          If you want to reference different column names in a search, the
  2588.          logic as stated in English is typically the same as it is in SQL.
  2589.          Usually there is no confusion between the and and the or unless
  2590.          you are dealing with the same column name. 
  2591.          Find all products in Washington with defects over 16%:
  2592.          
  2593.          select distinct code 
  2594.          from manu 
  2595.          where mst = 'WA' and defects > 16; 
  2596.           
  2597.          code  
  2598.          ----  
  2599.          DD    
  2600.           
  2601.          1 row selected 
  2602.  
  2603.  
  2604.                                 SELECT-6
  2605.  
  2606.          
  2607.          Generally, the use of a single and or an or in a where clause is
  2608.          more or less common sense unless you are referring to the same
  2609.          column name. What if you wanted to find all the products
  2610.          manufactured in Washington and Idaho? This has two meanings in
  2611.          everyday English: 
  2612.          
  2613.          1. Out of all the products we manufacture, I want a list of the
  2614.          ones we manufacture in Washington and a list of the ones we
  2615.          manufacture in Idaho. 
  2616.          
  2617.          2. Out of all the products we manufacture, I want a list of each
  2618.          one we manufacture in BOTH Washington and Idaho. 
  2619.          
  2620.          We will accept the first meaning in this example. It is
  2621.          interesting to note that we could have also said, "List all the
  2622.          products manufactured in Washington or Idaho." It seems odd that
  2623.          in English "or" can have the same meaning as "and". Even if you
  2624.          don't agree with my interpretation, beware that others do and
  2625.          that it may cause communication problems. 
  2626.          In the English version you use the "and" so there is a tendency
  2627.          to always use the "and" in the SQL version too. This would be
  2628.          wrong. The English perspective and the SQL perspective are
  2629.          different. The English perspective often looks at the whole group
  2630.          of items. The SQL perspective looks at one item at a time. To
  2631.          translate Washington and Idaho into SQL we look at it from its
  2632.          perspective. We will look at each item. If that item is
  2633.          manufactured in Washington or Idaho, we will add it to our table.
  2634.          Notice that when we look at it from the SQL perspective, we use
  2635.          the "or" instead of the "and". This not just a quirk of SQL
  2636.          logic, it is common to virtually all data bases. The statement
  2637.          below shows how to find out all the products manufactured in
  2638.          Washington and Idaho: 
  2639.          
  2640.          select distinct code 
  2641.          from manu 
  2642.          where mst='WA' or mst='ID'; 
  2643.           
  2644.          code  
  2645.          ----  
  2646.          GC    
  2647.          DD    
  2648.          NM    
  2649.           
  2650.          3 rows selected 
  2651.          
  2652.          It is interesting to note what the meaning would be if we used an
  2653.          and instead of an or. Would it tell us every product manufactured
  2654.          in BOTH Washington and Idaho? No, it wouldn't as you can see in
  2655.          the following:
  2656.          
  2657.          select distinct code 
  2658.          from manu 
  2659.          where mst='WA' and mst='ID'; 
  2660.           
  2661.          no rows found 
  2662.  
  2663.                                 SELECT-7
  2664.  
  2665.  
  2666.  
  2667.          
  2668.          Actually, it makes no sense. How could a state for an individual
  2669.          item be both WA and ID????? 
  2670.          
  2671.          But how WOULD you find out every product manufactured in both
  2672.          Washington and Idaho? The search strategy is rather complex and
  2673.          the topic is covered under joining tables and again when we
  2674.          discuss subqueries. 
  2675.          
  2676.          In order to express the opposite logic, you use the not but you
  2677.          have to be careful. The statement below shows how to find the
  2678.          products manufactured outside of Washington or Idaho. 
  2679.          
  2680.          select * 
  2681.          from manu 
  2682.          where not (mst='WA' or mst='ID'); 
  2683.          
  2684.          date     code mst defects qty  
  2685.          -------- ---- --- ------- ---  
  2686.          02/02/87 NM   CA       17  93  
  2687.          02/04/87 DD   AZ       12  25  
  2688.          02/04/87 DD   CA       15  25  
  2689.          02/06/87 GC   AZ        4  43  
  2690.           
  2691.          4 rows selected 
  2692.          
  2693.          Again, we must be careful about how we express the query in
  2694.          English. The query above cannot be translated as: Find the
  2695.          products NOT manufactured in Washington or Idaho. The query above
  2696.          retrieved some products that happen to be manufactured in Idaho
  2697.          or Washington. We really did not care. The only constraint we
  2698.          cared about was the state in which it was manufactured. The query
  2699.          could accurately be translated in fractured English: Find the
  2700.          products manufactured not in Washington or Idaho. By changing the
  2701.          statement to one that requests products not manufactured in
  2702.          Washington or Idaho, we change the words modified by "not" from
  2703.          the states to products manufactured. To find the products not
  2704.          manufactured in Washington or Idaho we must first find the set of
  2705.          all products manufactured in Washington or Idaho:
  2706.          
  2707.          select distinct code 
  2708.          from manu 
  2709.          where mst = 'WA' or mst = 'ID'; 
  2710.          
  2711.          code  
  2712.          ----  
  2713.          GC    
  2714.          DD    
  2715.          NM    
  2716.           
  2717.          3 rows selected 
  2718.  
  2719.  
  2720.  
  2721.  
  2722.                                 SELECT-8
  2723.  
  2724.  
  2725.  
  2726.          
  2727.          Then we must find all the products in the other states that are
  2728.          not in the above set of three products. We end up with the
  2729.          following which finds that there are not any products
  2730.          manufactured in the other states that are not manufactured in
  2731.          Washington and Idaho.
  2732.          
  2733.          select distinct code 
  2734.          from manu 
  2735.          where code != 'NM' and code != 'GC' and code != 'DD'; 
  2736.           
  2737.          no rows found
  2738.          
  2739.          Well, you may ask, what IS the select statement to find the
  2740.          products not manufactured in Washington or Idaho? Not so fast.
  2741.          Actually, it would require a subquery that is covered in the
  2742.          section on subqueries. 
  2743.          
  2744.          If I may digress...
  2745.          
  2746.          I know. Just a few pages into the basics of the select statement
  2747.          and you are ready to give up. Remember, the logic of SQL is not
  2748.          all that difficult. The main problem is that you do not think
  2749.          critically about the meaning of sentences. Much has been written
  2750.          about the problems of communication between humans and computers.
  2751.          Most of the problems are actually caused by the end-user and the
  2752.          "computer expert". I put the burden on the "computer expert" who
  2753.          should know enough about English to note the subtlties and
  2754.          ambiguities of what the end-user is requesting. This is just as
  2755.          relevant for interpreting queries as it is building complete
  2756.          application systems.
  2757.          
  2758.          Meanwhile, back at the ranch...
  2759.          
  2760.          Normally, if a condition is true, we add that row to the table.
  2761.          By using the not, if the condition is false, we add the row to
  2762.          the table. On the first row of the select statement to find
  2763.          products manufactured outside Idaho and Washington, the state is
  2764.          CA. It was selected because it is not equal to WA or ID. Just as
  2765.          we can express the same thought in English more than one way, we
  2766.          can do the same with SQL. We could have written:
  2767.          
  2768.          select * 
  2769.          from manu 
  2770.          where mst != 'WA' and mst != 'ID'; 
  2771.          OR 
  2772.          select * 
  2773.          from manu 
  2774.          where not (mst = 'WA') and not (mst = 'ID'); 
  2775.  
  2776.  
  2777.  
  2778.  
  2779.  
  2780.          
  2781.                                 SELECT-9
  2782.  
  2783.  
  2784.  
  2785.          
  2786.          What if we would have written or instead of and in the two
  2787.          examples above? Every row would have been selected. No matter
  2788.          what the state is, it would either be not equal to WA or not
  2789.          equal to ID! 
  2790.          
  2791.          Remember that whenever you use the not, you must enclose the
  2792.          expression in parentheses. 
  2793.          
  2794.          You can have as many ands and ors in a query as you need. What if
  2795.          you wanted all products in Washington and Idaho with defects less
  2796.          than 16%?  
  2797.          
  2798.          select * 
  2799.          from manu 
  2800.          where (mst='WA' or mst='ID') and defects < 16; 
  2801.           
  2802.          date     code mst defects qty  
  2803.          -------- ---- --- ------- ---  
  2804.          02/07/87 GC   ID       12  15  
  2805.          02/01/87 GC   ID        0  55  
  2806.          02/02/87 NM   WA       15  25  
  2807.           
  2808.          3 rows selected 
  2809.          
  2810.          We find that only two products are selected. Notice that
  2811.          parentheses enclose the or expression. This is because without
  2812.          the parentheses the and expression would have been executed
  2813.          first. Remember that without parentheses the ands are processed
  2814.          first and the ors are processed next. Not inserting the
  2815.          parentheses would have changed the meaning considerably:
  2816.          
  2817.          select * 
  2818.          from manu 
  2819.          where mst='WA' or mst='ID' and defects < 16; 
  2820.           
  2821.          date     code mst defects qty  
  2822.          -------- ---- --- ------- ---  
  2823.          02/07/87 GC   ID       12  15  
  2824.          02/01/87 GC   ID        0  55  
  2825.          02/03/87 DD   WA       22  46  
  2826.          02/02/87 NM   WA       15  25  
  2827.           
  2828.          4 rows selected 
  2829.          
  2830.          The above query is the equivalent of saying, "List all products
  2831.          in Washington and list all products in Idaho with defects under
  2832.          16%."  Another way of stating it is "In looking through all the
  2833.          products, if a product is manufactured in Washington or an Idaho
  2834.          product has under 16% defects, add it to the list." The important
  2835.          concept is that the 16% defects relates to the products
  2836.          manufactured in Idaho, not all products. 
  2837.          
  2838.  
  2839.  
  2840.                                 SELECT-10
  2841.  
  2842.  
  2843.  
  2844.  
  2845.          
  2846.          SETS (used with constants) 
  2847.          
  2848.          Instead of relating items one at a time, we can relate groups of
  2849.          items at once. These groups are called sets. They are enclosed
  2850.          parentheses and the constants are separated by commas. 
  2851.          
  2852.          You saw above how you can use =, !=, <, >, <=, and >=. We can
  2853.          expand that concept to include any and all.  This chapter has a
  2854.          brief introduction to sets.  Sets are the main topic of the
  2855.          chapters on subqueries where instead of using constants in sets,
  2856.          we use select statements.
  2857.          
  2858.          ANY 
  2859.          
  2860.          As you will see, the use of the any with constants is simply a
  2861.          short-hand method of writing a series of comparisons with ors.
  2862.          The any may be combined with any of the comparison operators:
  2863.          =any  equal to any 
  2864.          >any  greater than any 
  2865.          <any  less than any 
  2866.          !=any  not equal to any 
  2867.          >=any  greater than or equal to any 
  2868.          <=any  less than or equal to any 
  2869.          
  2870.          Although there are many possible combinations with any, very few
  2871.          are of any use. With constants, the only one that is typically
  2872.          used is =any. 
  2873.          
  2874.          Let's rewrite the query concerning all products manufactured in
  2875.          Washington or Idaho:
  2876.          
  2877.          select distinct code 
  2878.          from manu 
  2879.          where mst =any ('WA','ID'); 
  2880.          code  
  2881.          ----  
  2882.          GC    
  2883.          DD    
  2884.          NM    
  2885.           
  2886.          3 rows selected 
  2887.          
  2888.          Translated into English it would be: Select the description from
  2889.          the manufacturing table where the state of manufacture is equal
  2890.          to any of the following - WA or ID. 
  2891.          We can use numbers too. What if you wanted to know the basic
  2892.          information on products that have a percentage of defects of 12%
  2893.          or 15%?
  2894.  
  2895.  
  2896.  
  2897.          
  2898.  
  2899.                                  SELECT-11
  2900.  
  2901.  
  2902.  
  2903.          select date, code, mst 
  2904.          from manu 
  2905.          where defects =any (12,15); 
  2906.          date     code mst  
  2907.          -------- ---- ---  
  2908.          02/07/87 GC   ID   
  2909.          02/02/87 NM   WA   
  2910.          02/04/87 DD   AZ   
  2911.          02/04/87 DD   CA   
  2912.           
  2913.          4 rows selected 
  2914.          
  2915.          IN 
  2916.          
  2917.          An equivalent to =any is in. The above query could be translated:
  2918.          
  2919.          select date, code, mst
  2920.          from manu  
  2921.          where defects in (12,15);  
  2922.          
  2923.          The above two queries could be translated into a query without a
  2924.          set:
  2925.          
  2926.          select date, code, mst 
  2927.          from manu 
  2928.          where defects = 12 or defects = 15; 
  2929.          
  2930.          ALL
  2931.          
  2932.          The all can be combined with all the comparison operators just as
  2933.          was seen with the any. The only common use with constants occurs
  2934.          with the !=all which allows us to exclude a set of data. In the
  2935.          following statement we show information on products manufactured
  2936.          outside of Washington and Idaho.
  2937.          
  2938.          select date, code, mst 
  2939.          from manu 
  2940.          where mst !=all('WA','ID'); 
  2941.           
  2942.          date     code mst  
  2943.          -------- ---- ---  
  2944.          02/02/87 NM   CA   
  2945.          02/04/87 DD   AZ   
  2946.          02/04/87 DD   CA   
  2947.          02/06/87 GC   AZ   
  2948.           
  2949.          4 rows selected 
  2950.          
  2951.          Although we translated =any as "equal to any item in the set",
  2952.          !=all is usually translated as "not equal to any item in the
  2953.          set". Another way to state the above query is to find products
  2954.          manufactured in a state that is not any of the following -
  2955.          Washington and Idaho.  Confusing, isn't it??  Just remember that
  2956.  
  2957.  
  2958.                                 SELECT-12
  2959.  
  2960.  
  2961.  
  2962.  
  2963.  
  2964.          
  2965.          !=all is the opposite of =any.  This ambiguity in English is
  2966.          related to a riddle I heard Theo ask on the Cosby show:  "What
  2967.          two coins add up to 30 cents and one of them is not a quarter?" 
  2968.          The answer, of course, is a nickel and a quarter.  The nickel is
  2969.          not a quarter which satisfies the rule.  Theo was applying a
  2970.          !=any to the set when a typical listener would think that !=all
  2971.          was actually meant.
  2972.          
  2973.          BETWEEN constant AND constant 
  2974.          An easy way to select a range of values is use the between/and
  2975.          component of the where clause. The following shows how to find
  2976.          the basic information for products with defects between 12% and
  2977.          16%: 
  2978.          
  2979.          select date, code, mst, defects 
  2980.          from manu 
  2981.          where defects between 12 and 16; 
  2982.           
  2983.          date     code mst defects  
  2984.          -------- ---- --- -------  
  2985.          02/07/87 GC   ID       12  
  2986.          02/02/87 NM   WA       15  
  2987.          02/04/87 DD   AZ       12  
  2988.          02/04/87 DD   CA       15  
  2989.           
  2990.          4 rows selected 
  2991.          
  2992.          Notice that when we use the between, we include the 12 and the
  2993.          16. Unfortunately, the word "between" can have more than one
  2994.          meaning in standard English. If you say "The treasure is located
  2995.          between San Francisco and Walnut Creek", you would assume that
  2996.          the treasure is not IN San Francisco or Walnut Creek. That is,
  2997.          you would not include the end points - San Francisco or Walnut
  2998.          Creek. If you say "This insurance plan is available for those
  2999.          people between the ages of 18 and 65", you would assume that if
  3000.          you are 18 or 65, you are eligible. That is, you would include
  3001.          the end points. In English, when the word between is used with
  3002.          numbers, the end points are included. In other cases, the end
  3003.          points are not included. Silly, isn't it!! Just remember that in
  3004.          SQL, between includes the end points.
  3005.  
  3006.  
  3007.  
  3008.  
  3009.  
  3010.  
  3011.  
  3012.  
  3013.  
  3014.  
  3015.  
  3016.          
  3017.                                   SELECT-13
  3018.  
  3019.  
  3020.  
  3021.  
  3022.          IMPORTANCE OF THE NULL (UNKNOWN VALUE)
  3023.          Now that you understand the basics of how the where clause works,
  3024.          we need to complicate it a bit with considering the unknown value
  3025.          (the null).  If the where clause evaluates to TRUE, then the row
  3026.          is displayed, otherwise, it is not displayed.  In most non-SQL
  3027.          databases, the where clause only evaluates to TRUE and FALSE.  In
  3028.          SQL we have TRUE, FALSE, and UNKNOWN.  We can use truth tables to
  3029.          show the relationship.
  3030.          
  3031.           AND  |TRUE  FALSE  UNK     OR   |TRUE  FALSE  UNK
  3032.           ----------------------     -----------------------
  3033.           TRUE |TRUE  FALSE  UNK     TRUE |TRUE  TRUE   TRUE
  3034.           FALSE|FALSE FALSE  FALSE   FALSE|TRUE  FALSE  UNK   
  3035.           UNK  |UNK   FALSE  UNK     UNK  |TRUE  UNK    UNK
  3036.          
  3037.           NOT
  3038.           ------------
  3039.           TRUE  |FALSE
  3040.           FALSE |TRUE
  3041.           UNK   |UNK
  3042.          
  3043.          This can cause some confusing results until you are used to it.
  3044.          For example, there are nine rows in the manu table.  However, the
  3045.          two queries below result in a total of only eight rows.  
  3046.          
  3047.          select *
  3048.          from manu
  3049.          where defects = 15;
  3050.          
  3051.          date     code mst defects qty 
  3052.          -------- ---- --- ------- --- 
  3053.          02/02/87 NM   WA       15  25 
  3054.          02/04/87 DD   CA       15  25 
  3055.          
  3056.          2 rows selected
  3057.          
  3058.          select *
  3059.          from manu
  3060.          where defects != 15;
  3061.          
  3062.          date     code mst defects qty 
  3063.          -------- ---- --- ------- --- 
  3064.          02/07/87 GC   ID       12  15 
  3065.          02/01/87 GC   ID        0  55 
  3066.          02/02/87 NM   CA       17  93 
  3067.          02/03/87 DD   WA       22  46 
  3068.          02/04/87 DD   AZ       12  25 
  3069.          02/06/87 GC   AZ        4  43 
  3070.          
  3071.          6 rows selected
  3072.          
  3073.  
  3074.  
  3075.  
  3076.                                   SELECT-14
  3077.  
  3078.  
  3079.          At first glance you would think that defects are either equal to
  3080.          fifteen or not equal to fifteen.  However there is one instance
  3081.          where defects has an unknown value so it is not displayed.
  3082.          Intuitively you may be saying to yourself that since an unknown
  3083.          value is not equal to fifteen, it should be displayed, but that
  3084.          is not the way it works.  If you look at both the AND truth table
  3085.          and OR truth table, there is no difference between the false and
  3086.          the unknown since a result of FALSE or UNKNOWN will prevent a row
  3087.          from being displayed.  However, in the truth table for NOT, there
  3088.          is a difference. The opposite of unknown is still unknown.
  3089.          
  3090.          AGGREGATE FUNCTIONS - AVG, MIN, MAX, SUM, COUNT 
  3091.          
  3092.          All the aggregate functions operate on numeric columns except
  3093.          count which will operate on any columns. 
  3094.          
  3095.          SYNTAX: 
  3096.          
  3097.          AVG([DISTINCT] column_name) 
  3098.          MIN(column_name) 
  3099.          MAX(column_name) 
  3100.          SUM([DISTINCT]column_name) 
  3101.          COUNT([DISTINCT]column_name) 
  3102.          
  3103.          SUMMARY 
  3104.          
  3105.          AVG - without DISTINCT: The average of all values in a column
  3106.          AVG - with DISTINCT: The average of non-duplicate values 
  3107.          MIN - The minimum value in the column 
  3108.          MAX - The maximum value in the column 
  3109.          SUM - without DISTINCT: The sum of all values in the column 
  3110.          SUM - with DISTINCT: The sum of non-duplicate values 
  3111.          COUNT - without DISTINCT: the number of column values 
  3112.          COUNT - with DISTINCT: the number of non-duplicate column values 
  3113.          
  3114.          Notice that some of the functions have the distinct option. This
  3115.          will exclude all rows in the table which have duplicate column
  3116.          values. The follwing two examples show the difference. 
  3117.          select count(mst) 
  3118.          from manu; 
  3119.          CNT(mst)  
  3120.          --------  
  3121.                 9  
  3122.           
  3123.          9 rows selected 
  3124.          
  3125.          The above query can be translated as: 
  3126.          How many rows have values in the mst column? There are a total of
  3127.          9. This is not very useful because every row is going to have an
  3128.          entry for mst. The answer will always be the total number of rows
  3129.          in the table since the mst column was created with the "not null"
  3130.          constraint. 
  3131.          The following query is typically more useful. It answers the
  3132.          question: "How many different states manufacture products?"
  3133.  
  3134.  
  3135.                                   SELECT-15
  3136.  
  3137.  
  3138.          select count(distinct mst) 
  3139.          from manu; 
  3140.          CNT(mst)  
  3141.          --------  
  3142.                 4  
  3143.           
  3144.          Typically, when you are using a column name with count, you will
  3145.          modify it with distinct. When querying a table with a multiple
  3146.          part key, all columns will have the possibility of having
  3147.          duplicate entries. This is the case with the manu table with a
  3148.          key of date, code, mst. With such tables, you will modify the
  3149.          column name with distinct. When you query a table that has a key
  3150.          based on a single column, the only column you can be assured of
  3151.          not having duplicates is the key column. If you want to count all
  3152.          the rows in the table, there is a short-cut:
  3153.          
  3154.          select count(*) 
  3155.          from manu; 
  3156.          
  3157.          CNT(*)  
  3158.          ------  
  3159.               9  
  3160.           
  3161.          At this point, you may ask what use the column name is without
  3162.          the distinct modifier? It is that wonderful concept of the null
  3163.          that has been touched on before and will be discussed in more
  3164.          detail about the other functions. The count function will not
  3165.          count rows that have a null value in the column you are counting.
  3166.          Actually, all the functions skip rows with nulls. In the employee
  3167.          table, not everyone has a corresponding manager number. The entry
  3168.          for employees without a manager is a null (actually only the
  3169.          president doesn't have a manager in this table). The following
  3170.          tells us how many employees have managers.
  3171.          
  3172.          select count(mgrnum) 
  3173.          from emp; 
  3174.          CNT(mgrnum)  
  3175.          -----------  
  3176.                   14  
  3177.           
  3178.          15 rows selected 
  3179.          
  3180.          This can be contrasted with the following query. Notice how
  3181.          simply adding the word "distinct" completely changes the meaning
  3182.          of the query to finding how many managers there are in the
  3183.          company.
  3184.          
  3185.          select count(distinct mgrnum) 
  3186.          from emp; 
  3187.          
  3188.          CNT(mgrnum)  
  3189.          -----------  
  3190.                    7  
  3191.  
  3192.  
  3193.           
  3194.                                 SELECT-16
  3195.  
  3196.  
  3197.  
  3198.          
  3199.          The functions also can be used with the where clause. The
  3200.          following shows how many batches of product DD are in the table.
  3201.          
  3202.          select count(*) 
  3203.          from manu 
  3204.          where code = 'DD'; 
  3205.          
  3206.          CNT(*)  
  3207.          ------  
  3208.               4  
  3209.           
  3210.          4 rows selected 
  3211.           
  3212.          Before we discuss the other functions, let's look at the
  3213.          percentage of defects in Idaho:
  3214.          
  3215.          select * 
  3216.          from manu 
  3217.          where mst = 'ID'; 
  3218.          date     code mst defects qty  
  3219.          -------- ---- --- ------- ---  
  3220.          02/07/87 GC   ID       12  15  
  3221.          02/01/87 GC   ID        0  55  
  3222.          02/02/87 DD   ID           25  
  3223.           
  3224.          3 rows selected 
  3225.          
  3226.          In Idaho, the are three entries: 12, 0, and "nothing". This
  3227.          "nothing" is called a null. Nulls are important in relational
  3228.          data bases. It does not mean zero or blank. A null means that the
  3229.          data element is not relevant in the row. In our case, product DD
  3230.          is not tracked for defects like other products. This isn't to say
  3231.          that there are zero defects. It just means we have no entry.
  3232.          Because there are only two valid entries for defects in Idaho,
  3233.          the functions will not take into account the null data element.
  3234.          The average percentage of defects will be 12/2 = 6, not 12/3 = 4:
  3235.          
  3236.          select avg(defects) 
  3237.          from manu 
  3238.          where mst='ID'; 
  3239.          AVG(defects)  
  3240.          ------------  
  3241.                     6  
  3242.           
  3243.          3 rows selected 
  3244.          
  3245.          
  3246.          The sum function totals the numeric values in the column(s)
  3247.          requested. Below we sum the number of product DD that has been
  3248.          manufactured.
  3249.  
  3250.  
  3251.  
  3252.  
  3253.                                 SELECT-17
  3254.  
  3255.          
  3256.          select sum(qty) 
  3257.          from manu 
  3258.          where code = 'DD'; 
  3259.          
  3260.          SUM(qty)  
  3261.          --------  
  3262.               121  
  3263.           
  3264.          4 rows selected 
  3265.          
  3266.          More than one function can be used in a query: 
  3267.          
  3268.          
  3269.          select avg(qty), sum(qty) 
  3270.          from manu 
  3271.          where code = 'DD'; 
  3272.           
  3273.          AVG(qty) SUM(qty)  
  3274.          -------- --------  
  3275.                30      121  
  3276.           
  3277.          4 rows selected 
  3278.          
  3279.          
  3280.          Except for the group by clause, you cannot retrieve column values
  3281.          and functions based on column values in the same query. 
  3282.          
  3283.          COLUMN CALCULATIONS (*, /, +, -)
  3284.          
  3285.          Numeric columns can be used in calculations.  The following
  3286.          symbols are used:
  3287.          
  3288.          * = multiplication
  3289.          / = division
  3290.          + = addition
  3291.          - = subtraction
  3292.          The following shows the values if the defects doubled.
  3293.          
  3294.          select code, defects*2
  3295.          from manu;
  3296.          
  3297.          code      defects 
  3298.          ---- ------------ 
  3299.          GC             24 
  3300.          GC              0 
  3301.          NM             34 
  3302.          DD                
  3303.          DD             44 
  3304.          NM             30 
  3305.          DD             24 
  3306.          DD             30 
  3307.          GC              8 
  3308.          
  3309.          9 rows selected
  3310.  
  3311.  
  3312.                                 SELECT-18
  3313.  
  3314.  
  3315.  
  3316.          In a calculation, multiplication and division are processed
  3317.          first, then the addition and subtraction.  The order of
  3318.          processing can be changed by adding parentheses.  Calculations
  3319.          within parentheses are calculated first.  More than one column
  3320.          can be used in a calulation and even the same column can be
  3321.          referenced more than once.  The column name for the calculation
  3322.          is taken from the first column name however you can rename the
  3323.          column (as shown in the full documentation).  The data type for
  3324.          the calculation is based on the first column in the calculation.
  3325.  
  3326.          Calculations can occur also in the where clause but THERE ARE
  3327.          LIMITATIONS.  First, expressions are evaluated from left to right
  3328.          (mult & divide not necessarily first). Second, you cannot use
  3329.          parentheses.
  3330.          
  3331.          GROUP BY, HAVING
  3332.  
  3333.          The group by clause is normally used with aggregate functions. 
  3334.          It has two operations:
  3335.          
  3336.          1.  It sorts by the column name.
  3337.          
  3338.          2.  The aggregate functions only operate based on the rows that
  3339.          have the same column name.  The functions in essence create
  3340.          sub-totals based on the column name.
  3341.          
  3342.          What if we wanted to know the average defects in each state:
  3343.          
  3344.          select mst, avg(defects) 
  3345.          from manu 
  3346.          group by mst; 
  3347.           
  3348.          mst AVG(defects)  
  3349.          --- ------------  
  3350.          AZ             8  
  3351.          CA            16  
  3352.          ID             6  
  3353.          WA            18  
  3354.           
  3355.          4 rows selected 
  3356.          
  3357.          
  3358.          The column name after the group by must exist on the line with
  3359.          the select.  After the select you can only have column names in
  3360.          the group by and aggregate functions - nothing else.
  3361.          You can restrict the group by clause with the having component.
  3362.          In SSQL you are allowed one simple selection that includes the =.
  3363.          <, <=, >, >=, and !=.  As with the group by, the column name
  3364.          in the having component must exist in the select clause.
  3365.          If you only wanted a list of states with defects over 10% you
  3366.          would use the following:
  3367.          
  3368.  
  3369.  
  3370.  
  3371.                                 SELECT-19
  3372.  
  3373.  
  3374.  
  3375.          
  3376.          select mst, avg(defects) 
  3377.          from manu 
  3378.          group by mst having avg(defects) > 10; 
  3379.           
  3380.          mst AVG(defects)  
  3381.          --- ------------  
  3382.          CA            16  
  3383.          WA            18  
  3384.           
  3385.          2 rows selected 
  3386.          
  3387.          The group by clause can have up to two fields.  This is when you
  3388.          want a group within a group.  
  3389.          The group by clause can be used with the where clause.  When we
  3390.          found the average defects in each state we could have modified it
  3391.          by excluding product DD. 
  3392.          The where clause and the having clause are related.  However, the
  3393.          where clause operates on the whole table without regard for the
  3394.          grouping.  The having clause operates on the data that has
  3395.          already been grouped.  Because of the way the having clause
  3396.          works, most of the time the having clause contains an operation
  3397.          with an aggregate function because that is the basic purpose of
  3398.          the group by clause.
  3399.          
  3400.          ORDER BY
  3401.          
  3402.          The order by clause sorts the output of the table based on the
  3403.          column name(s) listed.  The original table is not changed. As
  3404.          with the group by clause, the order by clause can be used with
  3405.          the where clause.  For example, the following query will produce
  3406.          a list of manufacturing information sorted by defects for those
  3407.          items manufactured in Idaho.
  3408.          
  3409.          select date, code, defects 
  3410.          from manu 
  3411.          where mst = 'ID' 
  3412.          order by defects; 
  3413.           
  3414.          date     code defects  
  3415.          -------- ---- -------  
  3416.          02/02/87 DD            
  3417.          02/01/87 GC         0  
  3418.          02/07/87 GC        12  
  3419.           
  3420.          3 rows selected 
  3421.          
  3422.          You also can produce a sort within a sort.  The following query
  3423.          will produce an ordered list of dates and within each date the
  3424.          state will be sorted.
  3425.  
  3426.  
  3427.  
  3428.  
  3429.          
  3430.                                 SELECT-20
  3431.  
  3432.  
  3433.  
  3434.  
  3435.          
  3436.          select date, mst, code, qty 
  3437.          from manu 
  3438.          order by date, mst; 
  3439.           
  3440.          date     mst code qty  
  3441.          -------- --- ---- ---  
  3442.          02/01/87 ID  GC    55  
  3443.          02/02/87 CA  NM    93  
  3444.          02/02/87 ID  DD    25  
  3445.          02/02/87 WA  NM    25  
  3446.          02/03/87 WA  DD    46  
  3447.          02/04/87 AZ  DD    25  
  3448.          02/04/87 CA  DD    25  
  3449.          02/06/87 AZ  GC    43  
  3450.          02/07/87 ID  GC    15  
  3451.           
  3452.          9 rows selected 
  3453.          
  3454.          The order by clause assumes ascending order.  You can reverse the
  3455.          order by finding out in the full documentation
  3456.          
  3457.          When there are two columns to sort, one can be in ascending order
  3458.          while the other is in descending order. 
  3459.          In the current version of SSQL, you are limited to two sort
  3460.          columns.
  3461.          
  3462.          REDIRECTTO file_name
  3463.          
  3464.          Normally the report that is produced by the select command is
  3465.          displayed on the monitor.  However, with the redirectto clause,
  3466.          the report can be redirected to a text file or to the printer. 
  3467.          The text file is in standard ASCII text.  That is, there are no
  3468.          special characters in it.  The file name you give it must not
  3469.          have an extension because SSQL adds the extension ".txt".  
  3470.          If you wanted all the Arizona products stored in a file called
  3471.          ARIZ.TXT and you wanted the report sorted by product code, you
  3472.          would use the following query.
  3473.          
  3474.          select * 
  3475.          from  manu 
  3476.          where mst='AZ' 
  3477.          redirectto ariz 
  3478.          order by code; 
  3479.          
  3480.          The output would be stored in a file called ARIZ.TXT on your
  3481.          default drive.  To display the file on the monitor, you would
  3482.          exit SSQL and the following at the DOS prompt:
  3483.          
  3484.          type ariz.txt
  3485.  
  3486.  
  3487.  
  3488.          
  3489.                                 SELECT-21
  3490.  
  3491.  
  3492.  
  3493.  
  3494.  
  3495.          
  3496.          You also can have the report sent to the printer.  Replace the
  3497.          file name with prn or lpt1.  Make sure the printer is on when you
  3498.          use this option.  
  3499.          
  3500.          UNION
  3501.          The union command allows you to combine output from two or 
  3502.          three different select statements.  The two select statements 
  3503.          must have exactly the same output format - the same number of 
  3504.          columns and each column in the corresponding tables must be of 
  3505.          the same data type.  For the following example, I assume that 
  3506.          there are two tables with the same structure as SALES called 
  3507.          SALESCA and SALESAZ however it is not necessary that the tables 
  3508.          have the same structure, just the output columns.  The 
  3509.          following statement will get the customer code and quantity 
  3510.          from SALESCA for those customers who have purchased over 50 of 
  3511.          a particular item.  The output will also contain all the 
  3512.          customers and corresponding quanitities from the SALESAZ table. 
  3513.          The output is sorted by customer code.
  3514.  
  3515.          select cc,qty
  3516.          from salesca
  3517.          where qty > 50
  3518.          union
  3519.          select cc,qty
  3520.          from salesaz
  3521.          order by cc;
  3522.          
  3523.  
  3524.  
  3525.  
  3526.  
  3527.  
  3528.  
  3529.  
  3530.  
  3531.  
  3532.  
  3533.  
  3534.  
  3535.  
  3536.  
  3537.  
  3538.  
  3539.  
  3540.  
  3541.  
  3542.  
  3543.  
  3544.  
  3545.  
  3546.  
  3547.  
  3548.                                   SELECT-22
  3549.  
  3550.  
  3551.  
  3552.          JOINING TABLES
  3553.          
  3554.          
  3555.          Often, the data we need exists in more than one table. In order
  3556.          to extract the data, we need to select the appropriate columns
  3557.          and join the tables. The type of join primarily discussed is
  3558.          called a natural join but for the sake of brevity I will just use
  3559.          the word "join" alone. 
  3560.          Whenever we join tables, there must normally be a common column.
  3561.          Hear the common column contains the customer code. It is not
  3562.          important that the column names are different. The important
  3563.          aspect is that they describe precisely the same thing - i.e.,
  3564.          they have a common domain.
  3565.          In SQL, the join operation normally has three basic components:
  3566.          
  3567.          SELECT column names - for duplicate names, precede the column
  3568.          name with the table name and a period as in prod.code
  3569.          
  3570.          FROM table names separated by commas
  3571.          
  3572.          WHERE common columns are set to be equal
  3573.          
  3574.          The following shows how to combine the sales information from 
  3575.          the sales table and the customer name from cust:
  3576.          
  3577.          select name, pc, qty 
  3578.          from sales, cust
  3579.          where cc=code;
  3580.  
  3581.          name            pc qty 
  3582.          --------------- -- --- 
  3583.          Organomice      MW  23 
  3584.          Organomice      DD  34 
  3585.          QuarkCo         AB   2 
  3586.          Marswarp        MW  81 
  3587.          Technoharps     NM   3 
  3588.          Technoharps     MW  41 
  3589.          Technoharps     GC  33 
  3590.          Compugorp       MW 125 
  3591.          Compugorp       MW 947 
  3592.          Compugorp       DD 452 
  3593.          Compugorp       NM  32 
  3594.          
  3595.          name            pc qty 
  3596.          --------------- -- --- 
  3597.          QuarkCo         GC 845 
  3598.          Organomice      NM  45 
  3599.          Organomice      MW  73 
  3600.          Compugorp       GC 127 
  3601.          Compugorp       DD  32 
  3602.          
  3603.          16 rows selected
  3604.  
  3605.          MUCH MORE IN THE FULL DOCUMENTATION
  3606.  
  3607.                                 JOIN-1
  3608.  
  3609.  
  3610.  
  3611.  
  3612.          SIMPLE SUBQUERIES
  3613.          
  3614.          OVERVIEW
  3615.          
  3616.          In previous chapters, any comparison operation was done with
  3617.          actual values or a column name. Whenever we used the =, !=, <,
  3618.          > , <=, >=, in, all, or any there was a column name on one
  3619.          side and either a column name, an actual value or for the in,
  3620.          all, or any, a set of actual values on the other side. The
  3621.          problem is that often the values on right side of the comparison
  3622.          operation are not known until the query is made. In such cases
  3623.          the right side of the comparison is stated as a separate select
  3624.          command that is called a subquery. The result of the subquery is
  3625.          obtained first and the data is passed back to the previous query.
  3626.          Many queries can be linked together in this way.
  3627.          Another way of looking at it is that often, we need to break down
  3628.          our problem into more than one query. Each query will have its
  3629.          own select. We need subqueries when, in analyzing a problem, we
  3630.          find that we need information from one query before we can
  3631.          process another query. Sometimes we can either join tables or use
  3632.          a subquery. Typically, subqueries retrieve information more
  3633.          rapidly than joining tables.
  3634.          
  3635.          SUBQUERIES WITH =, !=, <, >, <=, AND >=
  3636.          
  3637.          These operators can be used with any subquery that produces a
  3638.          single value. It is commonly used with subqueries that contain  
  3639.          an aggregate function. The following shows the customer codes and
  3640.          quantity for those customers who have purchased more of product
  3641.          MW in a single purchase than the total purchased by customer BB.
  3642.          
  3643.          select  cc, qty
  3644.          from  sales
  3645.          where  pc = 'MW'
  3646.          and  qty >
  3647.            (select  sum(qty)
  3648.            from  sales
  3649.            where  cc = 'BB'
  3650.            and  pc = 'MW');
  3651.          
  3652.          cc qty
  3653.          -- ---
  3654.          EE  81
  3655.          AA 125
  3656.          AA 947
  3657.          ZZ  73
  3658.  
  3659.          4 rows selected
  3660.          
  3661.          This method also can be used with any column where we know it can
  3662.          only return a single value.
  3663.  
  3664.  
  3665.  
  3666.                                      SUB-1
  3667.  
  3668.  
  3669.  
  3670.  
  3671.  
  3672.          SET EXPRESSIONS - IN
  3673.          
  3674.          In the section on simple select statements, we used any and in
  3675.          with constants (actual values). The true power of the set
  3676.          expressions involves its use in subqueries. 
  3677.          
  3678.          We will first compare a join with a subquery. If we wanted to get
  3679.          product codes for all products purchased by customers in
  3680.          California, we could join the SALES table and the customer table.
  3681.          
  3682.          select  distinct pc
  3683.          from  sales, cust
  3684.          where  cc = code
  3685.          and  st = 'CA';
  3686.          
  3687.          pc 
  3688.          -- 
  3689.          MW 
  3690.          
  3691.          1 row selected
  3692.          
  3693.          
  3694.          Another approach would be to break it down into two queries. We
  3695.          know that we need a list of product codes from the SALES table.
  3696.          The SALES table has customer codes but it doesn't have
  3697.          information on states. Another way to state the problem is that
  3698.          we want all product codes from the SALES table where the customer
  3699.          code is in the set of customers that are in California. find the
  3700.          customers in California.
  3701.          
  3702.          
  3703.          select  distinct pc
  3704.          from  sales
  3705.          where  cc in
  3706.            (select  code
  3707.            from  cust
  3708.            where  st='CA');
  3709.          
  3710.          pc 
  3711.          -- 
  3712.          MW 
  3713.          
  3714.          1 row selected
  3715.          
  3716.          THERE IS MUCH MORE IN THE FULL DOCUMENTATION
  3717.         
  3718.         
  3719.         
  3720.         
  3721.         
  3722.         
  3723.         
  3724.          
  3725.                                      SUB-3
  3726.  
  3727.  
  3728.          CORRELATED SUBQUERIES 
  3729.           
  3730.          OVERVIEW 
  3731.           
  3732.          A correlated subquery is a subquery that refers to a table 
  3733.          OUTSIDE the subquery. This causes correlated subqueries to be 
  3734.          processed differently from simple subqueries. Simple subqueries 
  3735.          are processed once, and the result is passed back to the main 
  3736.          query. The correlated subquery is processed for every row in the
  3737.          
  3738.          main query. This allows us to process a subquery based on a 
  3739.          particular column value in each row of the main query. It can get
  3740.          even more complex with multiple levels of subqueries. With simple
  3741.          subqueries, each subquery is isolated and passes back a single 
  3742.          set of values to the previous level. With correlated subqueries,
  3743.          each subquery can depend on more than one of the previous levels.
  3744.          
  3745.          If we are working on the SALES table we can have a subquery that
  3746.          is processed for each customer or product, not the whole table. 
  3747.          Another way of looking at it is that for each row in the main 
  3748.          query we can take a value, say customer code, and process a 
  3749.          subquery based on the customer. The value it produces for the 
  3750.          customer can be compared to another value in the same row in the
  3751.          main query. We will do that in the next section when we want to 
  3752.          display the complete row in a SALES table for every customer 
  3753.          purchase where the quantity purchased is above average FOR THAT 
  3754.          CUSTOMER. With a simple subquery we could only compare customer 
  3755.          purchases with average SALES for the whole table or a SINGLE 
  3756.          customer. Using the correlated subquery is sometimes like being 
  3757.          able to compare values to a subquery with a GROUP BY.  
  3758.           
  3759.          Often, we just want to test for the existence of a row in a 
  3760.          subquery based on a value in the first level of the query so SQL
  3761.          has the exists predicate. By using the correlated subquery we can
  3762.          create some rather complex tests on sets of data.  
  3763.           
  3764.          AGGREGATE FUNCTIONS 
  3765.           
  3766.          Let's contrast the correlated subquery with a simple subquery 
  3767.          that is produced below: 
  3768.           
  3769.          select * 
  3770.          from sales  
  3771.          where qty > 
  3772.           (select avg(qty) 
  3773.           from sales); 
  3774.           
  3775.          date     bc cc sn pc qty  
  3776.          -------- -- -- -- -- ---  
  3777.          04/01/87 1A AA 10 MW 947  
  3778.          04/08/87 1A AA 10 DD 452  
  3779.          04/08/87 1B DD 11 GC 845  
  3780.           
  3781.          3 rows selected 
  3782.  
  3783.  
  3784.                                      COR-1
  3785.  
  3786.  
  3787.  
  3788.  
  3789.           
  3790.          It solves the problem for displaying the complete row in the 
  3791.          SALES table for every customer purchase where the quantity 
  3792.          purchased is above average (based on the complete SALES table). 
  3793.           
  3794.          The way a simple subquery works is that it is processed ONCE, and
  3795.          
  3796.          the result is passed back to the main query. 
  3797.          Now let's change the query a little bit. Now we want to display 
  3798.          the complete row in a SALES table for every customer purchase 
  3799.          where the quantity purchased is above average FOR THAT CUSTOMER.
  3800.          
  3801.          Without knowing much else, it should at least be obvious that we
  3802.          need to process the subquery more than once since the query 
  3803.          states that we need an average for EACH customer to compare the 
  3804.          quantity to. Actually, the correlated subquery is more 
  3805.          inefficient than this. Usually, for EVERY row in the first table,
  3806.          
  3807.          the subquery is processed: 
  3808.           
  3809.          select * 
  3810.          from sales sales1 
  3811.          where qty > 
  3812.           (select avg(qty) 
  3813.           from sales 
  3814.           where cc = sales1.cc); 
  3815.           
  3816.          date     bc cc sn pc qty  
  3817.          -------- -- -- -- -- ---  
  3818.          04/12/87 1B BB 27 MW  41  
  3819.          04/15/87 2A BB 33 GC  33  
  3820.          04/01/87 1A AA 10 MW 947  
  3821.          04/08/87 1A AA 10 DD 452  
  3822.          04/08/87 1B DD 11 GC 845  
  3823.          04/01/87 2A ZZ 12 NM  45  
  3824.          04/08/87 2A ZZ 12 MW  73  
  3825.           
  3826.          7 rows selected 
  3827.           
  3828.           
  3829.          On the last line of the subquery we set cc = sales1.cc. This 
  3830.          means that for every row in the first table, it will take the 
  3831.          customer code (sales1.cc), and compute the average quantity for 
  3832.          that customer. It will then determine whether the quantity is 
  3833.          greater than the average quantity. We had to use the alias sales1
  3834.          to distinguish one SALES table from the other. Following any 
  3835.          table name we can rename it to avoid confusion or ambiguity. The
  3836.          alias can be any name that would be a valid table name. 
  3837.           
  3838.  
  3839.  
  3840.  
  3841.  
  3842.  
  3843.                                      COR-2
  3844.  
  3845.  
  3846.  
  3847.  
  3848.  
  3849.          EXISTS/NOT EXISTS  
  3850.           
  3851.          The exists predicate tests for the existence of a row selected in
  3852.          a subquery BASED ON DATA IN THE CURRENT QUERY (and possibly outer
  3853.          queries). We do not care what data selected happens to be in the
  3854.          subquery, we just want to know that it exists. The following 
  3855.          shows how to find the names of products in the SALES table. 
  3856.           
  3857.          select descrip 
  3858.          from prod 
  3859.          where exists 
  3860.           (select * 
  3861.           from sales 
  3862.           where code = pc); 
  3863.           
  3864.          descrip          
  3865.          ---------------  
  3866.          Megawamp         
  3867.          Gigasnarf        
  3868.          Nanomouse        
  3869.          Dynamic Disk     
  3870.           
  3871.          4 rows selected 
  3872.           
  3873.          THE TRUE VALUE OF THE CORRELATED SUBQUERY CAN BE SEEN IN THE FULL
  3874.          DOCUMENTATION - ABOUT 40 PAGES!!! 
  3875.  
  3876.  
  3877.  
  3878.  
  3879.  
  3880.  
  3881.  
  3882.  
  3883.  
  3884.  
  3885.  
  3886.  
  3887.  
  3888.  
  3889.  
  3890.  
  3891.  
  3892.  
  3893.  
  3894.  
  3895.  
  3896.  
  3897.  
  3898.  
  3899.  
  3900.  
  3901.  
  3902.                                      COR-3
  3903.  
  3904.  
  3905.  
  3906.  
  3907.  
  3908.  
  3909.          CONVERTING ENGLISH TO SQL
  3910.          
  3911.          OVERVIEW
  3912.          The previous chapters emphasized the point of view of SQL and
  3913.          understanding all the parts.  This chapter is more concerned with
  3914.          the point of view of a person wanting to solve queries using SQL. 
  3915.          There are three pieces of important information - understanding
  3916.          the database, understanding the query, and finally writing the
  3917.          SQL statement.
  3918.          
  3919.          ***************************************************************
  3920.          **  THE FULL DOCUMENTATION HAS THE SQL STATEMENTS AND        **
  3921.          **  EXPLANATIONS.  THE FOLLOWING WILL GIVE YOU A GOOD        **
  3922.          **  IDEA OF THE FLEXIBILITY OF SQL AND THE VARIETY OF        **
  3923.          **  PROBLEMS THAT IT CAN SOLVE  (IT SHOULD ALSO CONVINCE     **
  3924.          **  YOU TO REGISTER SO YOU CAN GET THE FULL DOCUMENTATION!)  **
  3925.          ***************************************************************
  3926.          
  3927.          UNDERSTANDING THE DATABASE
  3928.          In the chapter on the example databases, when a column was
  3929.          described, any other common columns in other tables was mentioned
  3930.          also.  This commonality allows us to work with information that
  3931.          spans tables.  There are other ways to group this information
  3932.          that may be useful.  The first way is to group them by the common
  3933.          domains.  The Monolith Manufacturing database has four basic
  3934.          domains (I do not count date): state, product code, employee
  3935.          number, and branch code. We can group them as follows:
  3936.          
  3937.          
  3938.          
  3939.          NAME TABLES COLUMN NAME
  3940.          STATE CUST st
  3941.           MANU mst
  3942.           BRANCH st
  3943.          
  3944.          PRODUCT MANU code
  3945.          CODE PROD code
  3946.           SALES pc
  3947.          
  3948.          EMPLOYEE SALES sn
  3949.          NUMBER EMP enum
  3950.           EMP mgrnum
  3951.           BRANCH mgrnum
  3952.          
  3953.          BRANCH BRANCH code
  3954.          CODE SALES bc
  3955.          
  3956.          Whenever we join tables or use a subquery, we must use common
  3957.          domains so the above information is essential.
  3958.          
  3959.          
  3960.          
  3961.                                     ENG-1
  3962.  
  3963.  
  3964.  
  3965.          GENERAL APPROACH TO SOLVING THE QUERY
  3966.          (This section is only in the full documentation)
  3967.  
  3968.          The Numbering Scheme For Queries
  3969.          Each key word or words is given a number from 1 to 4.  The number
  3970.          is further divided into numbers to the right of a decimal as to
  3971.          how the keywords are used.  Each example is  followed by a
  3972.          letter.  Query 3.2B corresponds to the second example(B) for the
  3973.          second use(2) of keyword 3.  Queries preceded by an 'N' means
  3974.          that it is a negated version of the query.  There may be more
  3975.          than one way to negate it so the version is in the right-most
  3976.          position as in: N3.2B.2.
  3977.          
  3978.          1 - AND
  3979.          The and is used to refer to information in columns.  In its
  3980.          simplest form, it is used to select which columns to display.  It
  3981.          is commonly used to determine which rows to display.  As you will
  3982.          see from the examples, there are many ways to translate and into
  3983.          SQL.
  3984.          1.1 Used to describe which columns to display.
  3985.          1.1A List the date of manufacture, product code, and quantity.
  3986.          
  3987.          1.2 Used when you need or:
  3988.          1.2A List the rating for Organomice and Compugorp.
  3989.          1.2B List the dates of purchase for products MW and NM.
  3990.          
  3991.          1.3 Ambiguous 
  3992.          Solution could be an or a more complex construction.  Usually the
  3993.          ambiguity arises because we are referring to sets of values
  3994.          instead of single values.  The answer could be a union of the two
  3995.          sets (or) or an intersection (subquery). Query 1.2A asks for
  3996.          rating which will be a single value for each customer.  In query
  3997.          1.3A, we are concerned with two sets of values - products
  3998.          manufactured in Washington and products manufactured in Idaho. 
  3999.          Just because it refers to sets of values does not necessarily
  4000.          mean that it is ambiguous.  Query 1.2B refers to sets but (in my
  4001.          opinion) it is not ambiguous.  Contrast 1.2B with 1.3B which I
  4002.          think is ambiguous.
  4003.          1.3A  List the products manufactured in Washington and Idaho.
  4004.          1.3B  List the dates when products MW and NM were purchased.
  4005.          
  4006.          1.4. Not Ambiguous
  4007.          However the and translates into a more complex SQL statement. 
  4008.          What we are after here is often an intersection of the sets as
  4009.          you can see in 1.4A and 1.4B.  That is, we want values common to
  4010.          all sets. An intersection can normally be achieved through a
  4011.          series of subqueries.
  4012.          1.4A  List the products manufactured in both Washington and
  4013.          Idaho.
  4014.          1.4B  List the dates when all of the following products were
  4015.          purchased: MW, NM, and GC.
  4016.          1.4C  List the customers who are from Arizona and have purchased
  4017.          product MW.  
  4018.  
  4019.  
  4020.                                     ENG-2
  4021.  
  4022.  
  4023.  
  4024.  
  4025.  
  4026.          1.5 Definitely need an and in the where clause.  
  4027.          The and is used when we want to test two or more different
  4028.          columns in a row within a single table.
  4029.          1.5A  List the customers who are from Arizona and have a rating
  4030.          over 15.
  4031.          
  4032.          1.6 Implied and
  4033.          1.6A  List the Arizona customers who have a rating over 15.
  4034.          Same as 1.5A
  4035.          1.6B  List the Arizona customers who have purchased product MW.
  4036.          Same as 1.4C
  4037.          
  4038.          OR
  4039.          2.1  Normally translates to or:
  4040.          2.1A  List the customer codes for customers who have purchased MW
  4041.          or NM.
  4042.          2.1B  List the customers names for customers who have purchased
  4043.          MW or NM.
  4044.          2.1C  List the customer names for customers who are from
  4045.          California or have a rating less than 10.
  4046.          
  4047.          2.2 Comparison operators <= and >=.
  4048.          2.2A  List customers who have a rating greater than or equal to
  4049.          15.
  4050.          
  4051.          3 - WHICH, WHO, WHOSE, THAT, WITH, WHERE
  4052.          The above words have various meanings but I will emphasize their
  4053.          use in clauses.  Clauses connect parts of sentences.  Sometimes
  4054.          is makes a query clearer when it is converted to a form that has
  4055.          a clause.  The first six queries ask the same thing in different
  4056.          ways.  
  4057.          3.1A  Which customers have a rating over 10?
  4058.          3.1B  Who has a rating over 10?
  4059.          3.1C  List customers who have ratings over 10.
  4060.          3.1D  List customers with ratings over 10.
  4061.          3.1E  List every customer whose rating is over 10.
  4062.          3.1F  List every customer where the rating is over 10.
  4063.          Queries 3.1C through 3.1D are the most straightforward because
  4064.          the first part describes what is to be displayed and the second
  4065.          part describes the logic to determine which rows we want.  Many
  4066.          of the following can be rewritten in a similar manner but I will
  4067.          usually present only one approach.
  4068.          
  4069.          3.2  Link tables  
  4070.          3.2A  List the customer's states for customers who have purchased
  4071.          products  that are manufactured in Idaho.
  4072.          3.2B  Get branch codes for branches that sell products that are
  4073.          sold by branches that sell product DD. This is a rather
  4074.          convoluted one but shows the power of recognizing clauses. 
  4075.          Logically we want to find all the branches that sell product DD.
  4076.  
  4077.  
  4078.  
  4079.                                     ENG-3
  4080.  
  4081.  
  4082.  
  4083.  
  4084.          Then we want to take those branches and find all the products
  4085.          they sell.  With that set of products, we want to find all the
  4086.          branches that sell those products.  Notice how in 3.2B each
  4087.          subquery corresponds to each clause.  Be careful doing the
  4088.          conversion.  Sometimes the "that" does not have to be included. 
  4089.          Get branch codes for branches that sell products sold by branches
  4090.          that sell product DD.  In the previous sentence the "that" is
  4091.          missing between "products" and "sold".
  4092.          3.2C  List the names of employees who have sold products to
  4093.          Compugorp.
  4094.          3.2D. Get customer names and product names for customers who have
  4095.          purchased items that are manufactured outside their own state.
  4096.          3.2E  Get branch code, customer names and product names for those
  4097.          who purchase products that are manufactured in their own state
  4098.          from a branch in their own state.
  4099.          3.2F  Get branch numbers for branches that sell to both AA and
  4100.          BB.
  4101.          3.2G Who are the managers?
  4102.          3.2H  What are the names of managers who actually sold something?
  4103.          3.2I  What are the names of managers whose salespeople have sold
  4104.          products to Organomice?
  4105.          3.2J  What are the names of managers whose salespeople have sold
  4106.          products ONLY to Organomice? We have to add something to exclude
  4107.          salespeople who sold to a customer other than Organomice.
  4108.          3.2K List the names of Xero Xanadu's subordinates who sold
  4109.          Technowidgits and what were the quantities sold?
  4110.          3.2L  Get branch codes for branches that sell to a Washington or
  4111.          Arizona customer a product manufactured in Oregon.
  4112.          3.2M Get all pairs of state values where the branch in the first
  4113.          state sells to a customer in a second state.
  4114.          
  4115.          3.4  Implied that or who  
  4116.          The words in parentheses in the following three queries are
  4117.          optional.
  4118.          3.4A  Get product codes for products (that were) sold to any
  4119.          customer in California.
  4120.          3.4B  Get product numbers and corresponding customer names for
  4121.          products (that are) manufactured in the same state as a customer.
  4122.          3.4C  Get customer numbers for customers (who were) sold at least
  4123.          one product from a branch in the same state.
  4124.          
  4125.          4 - ANY/ALL
  4126.          Translating any and all cause the same sort of problems that were
  4127.          caused by and.  This is because the way we use a word in English
  4128.          may be different from the way we translate it to SQL.
  4129.          First of all, I will skip over any queries in which the any or
  4130.          all serve no purpose.  Often they are added for emphasis and CAN
  4131.          mean the same thing as in queries 4.1A and 4.1B.  Normally, the
  4132.          word any serves no purpose unless it is used in a comparison.
  4133.  
  4134.  
  4135.  
  4136.  
  4137.  
  4138.                                     ENG-4
  4139.  
  4140.  
  4141.  
  4142.          4.1  All and any not needed.  
  4143.          4.1A  Get all product codes for all products purchased by
  4144.          customers in California. 
  4145.          Same as 3.4A
  4146.          4.1B  Get any product code for any products purchased by any
  4147.          customer in California. 
  4148.          Same as 3.4A
  4149.          4.1C  Get product codes for products purchased by customers in
  4150.          California. 
  4151.          Same as 3.4A
  4152.          
  4153.          4.2  All used as part of a FORALL quantifier
  4154.          This was discussed in detail in the chapter on correlated
  4155.          subqueries. It is used when we want to compare one set of values
  4156.          to another set of values instead of comparing a single value to a
  4157.          set of values or comparing a single value to a single value.
  4158.          4.2A  Get product codes for products purchased by all customers.
  4159.          4.2B  Get product codes for products purchased by all customers
  4160.          in California.
  4161.          4.2C  Get product codes for products where the minimum defects is
  4162.          greater than 10 and has been purchased by all customers.
  4163.          4.2C  Get customer names for customers who have purchased all
  4164.          products.
  4165.          4.2D  States that manufacture all products sold by a branch in
  4166.          the same state.
  4167.          4.2E  Branches that have sold all the products manufactured in
  4168.          their own state.
  4169.          4.2F Branches that have sold all the products to all the
  4170.          customers.
  4171.          
  4172.          4.3 Using any and all in comparisons
  4173.          These are very deceiving.  The use of any normally translates to
  4174.          all in SQL or an equivalent construction.  This idea is discussed
  4175.          in the chapter on subqueries.
  4176.          4.3A  List products that have defects greater than any defect for
  4177.          products manufactured in Idaho.  Compare this to 4.3B.
  4178.          4.3B  List products that have defects greater than all defects
  4179.          for products manufactured in Idaho.
  4180.          Query 4.3A is normally interpreted as the same as 4.3B although
  4181.          logically it means something different.  If you think that they
  4182.          are different in common English then I guess SQL has distorted
  4183.          your thinking a bit.  When a tennis player says that he is better
  4184.          than ANY tennis player, we assume that he means that he is better
  4185.          than ALL tennis players.  The confusion is caused by the fact
  4186.          that in most contexts any and all are very different as in the
  4187.          following two sentences.  Give me any book.  Give me all the
  4188.          books.
  4189.          4.3C  List products that have defects less than any (all) defects
  4190.          for products manufactured in Idaho.
  4191.          4.3D  List products that have defects the same as any defects for
  4192.          products manufactured in Idaho.  In this case we cannot replace
  4193.          the "any" with an "all" and retain the same meaning.
  4194.          
  4195.  
  4196.  
  4197.                                     ENG-5
  4198.  
  4199.  
  4200.  
  4201.  
  4202.  
  4203.          N - NEGATION
  4204.          In this section I will take many of the above queries and negate
  4205.          them.
  4206.          N1.2a List the rating for all except Organomice and Compugorp.
  4207.          N1.3A.1  List the products manufactured in neither Washington nor
  4208.          Idaho.
  4209.          N1.3A.2 List the products not manufactured in both Washington and
  4210.          Idaho.
  4211.          N1.3B.1  List the dates that products MW or NM were not
  4212.          purchased.
  4213.          N1.3B.2  List the dates that products other than MW or NM were
  4214.          purchased.
  4215.          N1.4B.1  List the dates when all of the following products were
  4216.          not purchased: MW, NM, and GC.
  4217.          N1.4B.2  List the dates when none of the following products were
  4218.          purchased: MW, NM, and GC.
  4219.          N1.4B.3  List the dates when something other than the following
  4220.          products were purchased: MW, NM, and GC.
  4221.          N1.4C.1  List the customers who are from Arizona and have not
  4222.          purchased product MW.  
  4223.          N2.1B.1  List the customers names for customers who have not
  4224.          purchased MW or NM.
  4225.          N2.1B.2  List the customers names for customers have purchased
  4226.          products other than MW and NM.
  4227.          The difference between N2.1B.1 and N2.1B.2 is that the first one
  4228.          would exclude any customer who has purchased MW or NM.  The
  4229.          second one would include the customer as long as the customer
  4230.          purchased another product.
  4231.          N3.2A.1  List the customer's states for those customers who have
  4232.          not purchased products manufactured in Idaho.
  4233.          N3.2A.2  List the customer's states for those customers who have 
  4234.          purchased products not manufactured in Idaho.
  4235.          N3.2A.2  List the customers' states for those customers who have 
  4236.          purchased products manufactured outside (not in) Idaho.
  4237.          The above differs from the previous query in that it will include
  4238.          any product manufactured in Idaho IF it is manufactured outside
  4239.          Idaho.
  4240.          N3.2B.1  Get branch codes for branches that do not sell products
  4241.          that are sold by branches that sell product DD.
  4242.          N3.2B.2  Get branch codes for branches that sell products that
  4243.          are not sold by branches that sell product DD.
  4244.          N3.2B.3  Get branch codes for branches that sell products that
  4245.          are sold by branches that do not sell product DD.
  4246.          The negation is on selling product DD.  This is different from
  4247.          saying: "...branches that sell products other than DD".  
  4248.          N3.2C.1  List the names of employees who have not sold products
  4249.          to Compugorp.
  4250.          N3.2D.1 Get customer names and product names for customers who
  4251.          have purchased items not manufactured outside their own state.
  4252.          N3.2D.2 Get customer names for customers who have not purchased
  4253.          items manufactured outside their own state.  
  4254.  
  4255.  
  4256.                                     ENG-6
  4257.  
  4258.  
  4259.  
  4260.  
  4261.  
  4262.          N3.2D.3 Get customer names for customers who have only purchased
  4263.          items in their own state. 
  4264.          At first glance N3.2D.3 seems the same as N3.2D.2 but N3.2D.2
  4265.          would display customers who have not purchased anything.  We have
  4266.          to add some more to make sure that the customer actually made a
  4267.          purchase.
  4268.          N3.2F.1  Get branch codes for branches that do not sell to both
  4269.          AA and BB.
  4270.          N3.2F.1  Get branch codes for branches that sell to neither AA
  4271.          nor BB.
  4272.          N3.2F.1  Get branch codes for branches that do not sell to AA or
  4273.          BB.
  4274.          N3.2G.1  What are the names of managers who did not sell
  4275.          anything?
  4276.          N3.2I.1  What are the names of managers whose salespeople have
  4277.          not sold products to Organomice?
  4278.          N3.2I.2  What are the names of managers whose salespeople have 
  4279.          sold products to everyone except Organomice?  This becomes a
  4280.          tough one because the opposite of "only Organomice" in 3.2I is
  4281.          "everyone except Organomice" and "everyone" corresponds to the
  4282.          FORALL quantifier covered in the chapter on correlated
  4283.          subqueries.  The core of this query has to do with "salespeople
  4284.          selling to ALL customers (except Organomice)".
  4285.          N3.2L.1  Get branch codes for branches that sell to a Washington
  4286.          or Arizona customer a product not manufactured in Oregon.
  4287.          N3.2L.2  Get branch codes for branches that sell to a Washington
  4288.          or Arizona customer a product manufactured outside of Oregon.
  4289.          N4.2A.1  Get product codes for products not purchased by all
  4290.          customers.
  4291.          N4.2A.2  Get product codes for products purchased by none of the
  4292.          customers.
  4293.          N4.2D.1  States that do not manufacture all products sold by a
  4294.          branch in the same state.
  4295.          N4.2D.2  States that manufacture no products sold by a branch in
  4296.          the same state.
  4297.          N4.2E.1  Branches that have not sold all the products
  4298.          manufactured in their own state.
  4299.          N4.2E.2  Branches that have sold none of the products
  4300.          manufactured in their own state.
  4301.          N4.2E.3  Branches that have sold all the products not
  4302.          manufactured in their own state.
  4303.          N4.2E.4  Branches that have sold all the products manufactured
  4304.          outside their own state.
  4305.  
  4306.          
  4307.          
  4308.          
  4309.          
  4310.          
  4311.          
  4312.          
  4313.          
  4314.          
  4315.                                     ENG-7
  4316.  
  4317.  
  4318.  
  4319.  
  4320.  
  4321.          CREATE  TABLE
  4322.          
  4323.          OVERVIEW
  4324.          The CREATE TABLE command is used to create a table file. You can
  4325.          control the contents of the columns in two ways.  You can prevent
  4326.          a column from being null and you can make sure that a column or
  4327.          set of columns never contain duplicate values.  These
  4328.          restrictions allow us to maintain valid primary keys when we use
  4329.          the INSERT command to add rows to a table or the UPDATE command
  4330.          to modify values in a table.
  4331.          
  4332.          SYNTAX
  4333.          
  4334.          CREATE TABLE table_name (
  4335.            column_definition [, column_definition...]
  4336.            [, uniqueness_constraint]
  4337.          );
  4338.  
  4339.          EXAMPLE:
  4340.          The statement below shows how to create the cust table that  the
  4341.          documentation uses. 
  4342.          
  4343.          create table cust ( 
  4344.          code char(2) not null unique,   
  4345.          name char(15) not null,
  4346.          st char(2) not null,
  4347.          rating numeric(2)
  4348.          );
  4349.          
  4350.          You can define up to 27 columns in a table.
  4351.          As with all SQL commands, they can be in uppercase or lowercase. 
  4352.          After the name of the table, parentheses enclose the column
  4353.          definitions. The column definitions are put on separate lines to
  4354.          aid in readability.  SQL never requires anything to be put on
  4355.          separate lines or have specific spacing. Note that all column
  4356.          definitions except the last one has a comma after it.
  4357.          The above command states that there will be four columns in the
  4358.          cust table:
  4359.          
  4360.          code can have up to two characters.  It is the primary key so
  4361.          nulls will not be allowed and each code will be unique.
  4362.          
  4363.          name can have up to fifteen characters. It must contain a value.
  4364.          
  4365.          st   is the state postal code and it can have up to 2 characters.
  4366.          It must contain a value.
  4367.          
  4368.          rating is the customer rating.  Since NOT NULL is not specified,
  4369.          the customer rating is optional - it does not have to be entered.
  4370.  
  4371.  
  4372.  
  4373.  
  4374.                                       CREATE-1
  4375.  
  4376.  
  4377.  
  4378.  
  4379.  
  4380.          COMPONENTS OF CREATE TABLE
  4381.          
  4382.          table_name
  4383.          A table name can be from 1 to 10 characters.  The first eight
  4384.          characters must be unique.  The first character must be a letter 
  4385.          of the alphabet.  The rest can be letters or digits, _
  4386.          (underscore), or #.  The table files are created on the disk as in
  4387.          table_name.DBF and table_name.SQD.  For example, the cust 
  4388.          table, created above would be stored as CUST.DBF and CUST.SQD 
  4389.          on your disk.  However, from SSQL, you would always refer to it 
  4390.          as CUST.  Since SSQL adds the extension of DBF and SQD to all 
  4391.          table files, you must not use a period in your table name.   
  4392.          
  4393.          column_definition
  4394.          
  4395.          column_name data_type [NOT NULL [UNIQUE]]
  4396.          
  4397.          column_name
  4398.          A column name can be from 1 to 10 characters.  The first
  4399.          character must be a letter of the alphabet.  The rest can be
  4400.          letters or digits.  In creating column names remember that when
  4401.          you display a table, the full column name is displayed too as the
  4402.          heading.  Long column names tend to fill the screen (or printer)
  4403.          very rapidly when you want to display many columns.  The column
  4404.          name is displayed exactly as you type it, retaining the uppercase
  4405.          and lowercase letters.  The create statement above created the
  4406.          column names and hence the headings in lowercase letters.  We
  4407.          could have written it as shown below.
  4408.          
  4409.          create table cust ( 
  4410.          CODE char(2) not null unique,   
  4411.          NAME char(15) not null,
  4412.          ST char(2) not null,
  4413.          RATING numeric(2)
  4414.          );
  4415.          
  4416.          With the statement above, whenever we display data from the
  4417.          table, the headings would in uppercase.
  4418.  
  4419.          data_type
  4420.          The data types in SQL fall into two broad categories - numbers
  4421.          and characters.  Within the numbers category, there are exact
  4422.          numeric types and approximate numeric types.  However, all 
  4423.          numeric data types are converted to the dBase numeric data 
  4424.          type.  The other types are included to maintain compatibility 
  4425.          with ANSI SQL.  Two non-standard data have been added to 
  4426.          maintain compatibility with dBase - Date and Logical.
  4427.  
  4428.  
  4429.  
  4430.  
  4431.          
  4432.  
  4433.                                 CREATE-2
  4434.  
  4435.  
  4436.          Numeric
  4437.          
  4438.           (Exact Numeric)
  4439.           NUMERIC[(length [,decimal_places])]
  4440.           DECIMAL[(length [,decimal_places])]
  4441.           DEC[(length [,decimal_places])]
  4442.           INTEGER
  4443.           INT
  4444.           SMALLINT
  4445.           (Approximate Numeric covered in the full documentation)
  4446.  
  4447.          When you use numeric data types the values are always
  4448.          right-justified (values are pushed to the right so all the
  4449.          decimal lines up).  Data must be of this type in order to use any
  4450.          of the numeric functions such as avg, max, min, and sum.  
  4451.          The first three data types in the exact numeric category -
  4452.          NUMERIC, DECIMAL, and DEC, can be used interchangeably.  It
  4453.          sounds a little odd that a data type called DECIMAL does not
  4454.          necessarily mean that the contents of the column will contain a
  4455.          decimal place since the modifier decimal_places is optional. 
  4456.          
  4457.          length (optional)
  4458.          The length of the column be up to 12 digits (including the
  4459.          decimal place. Without this specification, the length is 1.
  4460.          
  4461.          decimal_places (optional)
  4462.          The number of places to the right of the decimal.  For Example:  
  4463.          
  4464.          cost  numeric(5,2)
  4465.          
  4466.          This would allow a maximum of 99.99 to be stored in the column.
  4467.          
  4468.          This also could be defined as:
  4469.          
  4470.           cost decimal(5,2)
  4471.          or 
  4472.           cost dec(5,2)
  4473.          
  4474.          It is allowable to use whole numbers even though you define it as
  4475.          having decimals.  For example, you want to enter grades that are
  4476.          from  0 to 100 but when you calculate grade averages, you want it
  4477.          calculated to one tenth of a grade point.  You would define the
  4478.          column as:
  4479.          
  4480.           grade  numeric(5,1)
  4481.          
  4482.          You would enter the grades as whole numbers but when the average
  4483.          is calculated, the decimal would be included. 
  4484.          With NUMERIC, DECIMAL and DEC, if you omit the dec_places
  4485.          modifier, the result is a whole number.
  4486.          
  4487.          Data types such as INTEGER (which is the same as INT) and
  4488.          SMALLINT have lengths associated with them.  The ANSI standards
  4489.          state that the lengths shall be determined by the implementor so
  4490.          I have picked lengths of ten and five respectively.
  4491.  
  4492.                                CREATE-3
  4493.  
  4494.          
  4495.          INTEGER is the same as numeric(10) or decimal(10) or dec(10)
  4496.          SMALLINT is the same as numeric(5) or decimal(5) or dec(5)
  4497.          
  4498.          You can see that although there are six exact numeric data types,
  4499.          you only need one.
  4500.          
  4501.          Characters
  4502.          
  4503.           CHARACTER[(length)]
  4504.           CHAR[(length)]
  4505.  
  4506.          These data types can be used for any column that you do not use
  4507.          in a calculation.  Although the data is usually a combination of
  4508.          alphabetic and numeric data, it is alright if the column just
  4509.          contains digits.  The characters are left-justified.  The maximum
  4510.          column width is 80.  CHARACTER and CHAR can be used
  4511.          interchangeably.  If you omit the length modifier, then the
  4512.          length of the column is one.
  4513.          
  4514.          Date
  4515.            DATE
  4516.            The DATE data type creates a column of 8 characters.  Dates 
  4517.          are entered as mm/dd/yy.  
  4518.          
  4519.          Logical
  4520.            LOGICAL - A one character column that can store Y, y, N, n, 
  4521.          T, t, F, f, or ? 
  4522.  
  4523.          NOT NULL
  4524.          This modifier to a column definition will ensure that there is
  4525.          always a value for this column. It prevents the INSERT and UPDATE
  4526.          commands from allowing a column to contain a null value. When
  4527.          used with the UNIQUE modifier, it is used to specify a primary
  4528.          key.  There are special commands to retrieve rows that only have
  4529.          null values in a particular column or to exclude rows that have
  4530.          null values in a particular column.
  4531.          
  4532.          UNIQUE
  4533.          This ensures that each value in the column is unique.  If an
  4534.          attempt is made to enter a duplicate value when inserting a new
  4535.          row, an error results and the row is not added to the table.  If
  4536.          you use unique, it must be used with NOT NULL. This is typically
  4537.          used when a single column is a primary key. 
  4538.          
  4539.          Uniqueness_constraint (covered in full documentation)
  4540.          
  4541.          CHECKING THE STRUCTURE OF A TABLE
  4542.          In order to display the create command used to create the table,
  4543.          type STRUCT followed by the table name.
  4544.          
  4545.  
  4546.  
  4547.  
  4548.  
  4549.  
  4550.  
  4551.                                      CREATE-4
  4552.  
  4553.  
  4554.          CREATE A VIEW
  4555.  
  4556.          OVERVIEW
  4557.          A view is a derived table.  A view describes an alternative
  4558.          access to columns and tables that already exist.  The create
  4559.          table command allowed us to create a physical table that is also
  4560.          called a base table.  With a base table every column corresponds
  4561.          to the source of data.  We can always use the insert, update, and
  4562.          delete commands on base tables.  Views never exist as permanent
  4563.          tables.  Whenever you query a view, it creates a temporary table
  4564.          based on your view.  When the query is complete, the temporary
  4565.          table is erased.
  4566.          The view can reference an existing column under a different name
  4567.          or keep the original name. The view can be based on more than one
  4568.          table.  You can reference as few or as many columns you want in
  4569.          the tables you select.
  4570.          
  4571.          SYNTAX
  4572.          
  4573.          CREATE VIEW view_name [(column_name [,column_name...])] AS
  4574.          select_statement
  4575.          
  4576.          EXAMPLES:
  4577.          Create a view which only shows less than the full number of
  4578.          columns in a table.  In a commercial database system, this can be
  4579.          used to prevent users from seeing sensitive data.  For example,
  4580.          The employee table may include salary information.  A view of
  4581.          that table could have everything except the salary information.
  4582.          It is necessary to have some background in the use of the select
  4583.          command before attempting to create a view of a table.  The
  4584.          statement below shows the creation of a view called custa.   It
  4585.          is based on the cust table that has four columns:  code, name,
  4586.          st, and rating.
  4587.          
  4588.          create view custa as
  4589.          select code, name, st
  4590.          from cust;
  4591.          
  4592.          The column names are the same as they are in the original table. 
  4593.          The only difference is that rating is not part of the view.
  4594.          When you use view custa in a query, it acts just like a regular
  4595.          table.  When it displays all the columns as shown below, you only
  4596.          see the three columns specified in the view.  
  4597.          
  4598.          select * 
  4599.          from custa; 
  4600.          
  4601.          code name            st  
  4602.          ---- --------------- --  
  4603.          AA   Compugorp       WA  
  4604.          BB   Technoharps     OR  
  4605.          ZZ   Organomice      AZ  
  4606.          DD   QuarkCo         AZ  
  4607.          EE   Marswarp        CA  
  4608.          FF   Multicrud       NV  
  4609.          
  4610.                                      VIEW-1
  4611.  
  4612.  
  4613.  
  4614.  
  4615.  
  4616.          We have no access to the rating column when using the custa view.
  4617.          
  4618.          RULES FOR USING VIEWS
  4619.          
  4620.          It is used in a select statement, NOT an insert, update, or
  4621.          delete statement. To erase the view, use the drop view statement.
  4622.          
  4623.          Can contain any select statement except one that has redirectto. 
  4624.          
  4625.          Views should only be used when they are absolutely needed.  They
  4626.          can add much confusion to a database design because it is easy to
  4627.          forget which are tables and which are views.
  4628.          
  4629.          (MORE IN THE FULL DOCUMENTATION)
  4630.  
  4631.  
  4632.  
  4633.  
  4634.  
  4635.  
  4636.  
  4637.  
  4638.  
  4639.  
  4640.  
  4641.  
  4642.  
  4643.  
  4644.  
  4645.  
  4646.  
  4647.  
  4648.  
  4649.  
  4650.  
  4651.  
  4652.  
  4653.  
  4654.  
  4655.  
  4656.  
  4657.  
  4658.  
  4659.  
  4660.  
  4661.  
  4662.  
  4663.  
  4664.  
  4665.  
  4666.  
  4667.  
  4668.  
  4669.                                       VIEW-2
  4670.  
  4671.  
  4672.  
  4673.  
  4674.  
  4675.  
  4676.          DROP TABLE/VIEW
  4677.  
  4678.          OVERVIEW
  4679.          The drop command is used to erase a table or view from the disk.
  4680.          The drop table command is used to erase the description of the
  4681.          table from the disk.  The drop view command erases the view but
  4682.          can never alter data or tables since the view simply describes
  4683.          access to a table or tables.
  4684.          
  4685.          SYNTAX
  4686.          
  4687.          DROP TABLE table_name;
  4688.          or
  4689.          DROP VIEW view_name;
  4690.          
  4691.          EXAMPLES:
  4692.          
  4693.          drop table cust;
  4694.          drop view custa; 
  4695.          
  4696.          COMPONENTS OF THE DROP COMMAND
  4697.          
  4698.          table_name
  4699.          The table_name must be a valid table name which contains NO data. 
  4700.          In order to delete all the data you can first type:
  4701.          
  4702.          delete from table_name;
  4703.          
  4704.          The delete command erases the data and the drop table command 
  4705.          erases the column descriptions. 
  4706.          
  4707.          view_name
  4708.          The view_name must be a valid view name.  Since no data is
  4709.          affected it can be used at any time.
  4710.  
  4711.  
  4712.  
  4713.  
  4714.  
  4715.  
  4716.  
  4717.  
  4718.  
  4719.  
  4720.  
  4721.  
  4722.  
  4723.  
  4724.  
  4725.  
  4726.  
  4727.  
  4728.                                 DROP-1
  4729.  
  4730.  
  4731.           INSERT DATA INTO A TABLE
  4732.  
  4733.           OVERVIEW
  4734.           The ANSI standards define two ways to add data to a table. One
  4735.           requires us to type each value for each column in each row. The
  4736.           other copies data from one table and puts it in another. It is
  4737.           very useful for making corrections to tables. I only describe the
  4738.           first type in this documentation.  Registered users find out
  4739.           about the more advanced use of the insert command and a special,
  4740.           non-ANSI command which makes inserting data MUCH easier.
  4741.           
  4742.           Both insert commands maintain the restrictions we may have
  4743.           imposed through the CREATE TABLE command.  We could have
  4744.           specified NOT NULL and UNIQUE to prevent certain types of data
  4745.           errors in our tables.
  4746.           
  4747.           INSERT VALUES - SYNTAX
  4748.           
  4749.           INSERT INTO table_name [column_name [,column_name...]]
  4750.           VALUES (column_value [,column_value]);
  4751.           
  4752.           EXAMPLES:
  4753.           
  4754.           The first example shows the typical way to use the insert command
  4755.           since it does not reference any column names.  The insert command
  4756.           assumes that you will enter the data in the order that they were
  4757.           created in the table.  The second example shows that column names
  4758.           can be referenced. The third example shows that the data entry
  4759.           does not have to be in the order in which the columns were
  4760.           created.  Compare the order of the values to the first example.
  4761.           insert into cust values('AA','Compugorp','WA',20);
  4762.           or
  4763.           insert into cust code, name, st, rating
  4764.           values('AA','Compugorp','WA',20);
  4765.           or
  4766.           insert into cust name, code, rating, st 
  4767.           values('Compugorp','AA',20,'WA');
  4768.           
  4769.           MORE DETAIL ON THE COMPONENTS OF THE SYNTAX
  4770.           
  4771.           table_name
  4772.           
  4773.           Any existing table in your database.
  4774.           
  4775.           column_name
  4776.           
  4777.           Normally column names are not used with the insert command.  This
  4778.           is because the insert command assumes that we are going to insert
  4779.           values for all the columns in the table in the order in which
  4780.           they were created. You saw this in the first example.  It has the
  4781.           same effect as the second example.  In the third example we want
  4782.           to insert data in a different order.  This could be useful if the
  4783.           source document that we are getting the data from presents the
  4784.           data in a different order from which the table was designed.  
  4785.  
  4786.  
  4787.                                    INSERT-1
  4788.  
  4789.  
  4790.  
  4791.           column_value
  4792.           There are three types of column values: character, numeric and
  4793.           null.
  4794.           
  4795.           Character data
  4796.           Character data must be enclosed in quotes or apostrophes. The
  4797.           first example above could have been entered as:
  4798.           
  4799.           insert into cust values("AA","Compugorp","WA",20);
  4800.           
  4801.           Although you can enter SQL commands in uppercase or lowercase,
  4802.           care must be taken when entering character data since everything
  4803.           is stored exactly as entered.  This can create problems when we
  4804.           are retrieving data.  Let's assume that Compugorp purchased some
  4805.           Megawamps so we insert the following information into the sales
  4806.           table: date, branch code, customer code, employee number, product
  4807.           code and quantity.
  4808.           
  4809.           insert into sales values('04/01/87','1A','aa',10,'MW',947);
  4810.           
  4811.           Although SQL would accept the above insert command, we made a
  4812.           critical logical error.  The correct customer code for Compugorp
  4813.           is 'AA', NOT 'aa'.  This is an error that is rather difficult to
  4814.           detect.  Any time we relate the sales table with the cust table,
  4815.           the above row in the sales table will not be retrieved.  This
  4816.           could cause reports to disagree.  The section on correlated
  4817.           subqueries explains how to detect this problem.  Technically, it
  4818.           is called referential integrity.
  4819.           Another mistake that is easily made involves accidentally having
  4820.           leading or trailing spaces in a character value.  If we inserted
  4821.           the data for Compugorp with the following:
  4822.           
  4823.           insert into cust values('AA','Compugorp ','WA',20);
  4824.           
  4825.           You will notice the space after the last 'p' in Compugorp.  There
  4826.           will not be a problem with it until you try a query that includes
  4827.           the name of the company as shown below.
  4828.           select *
  4829.           from cust 
  4830.           where name = 'Compugorp';
  4831.           
  4832.           The row with Compugorp will not be found because the query did
  4833.           not contain the space after the last p!  This is a very
  4834.           frustrating error as I have seen quite a few students accuse me
  4835.           of having a serious malfunction in my program with the look on
  4836.           their faces suggesting what I could do with SSQL.
  4837.           All columns have a particular length associated with them.  This
  4838.           denotes the maximum number of characters that the column can
  4839.           contain.  When we created the cust table, the name column was
  4840.           defined as char(15) which means that the maximum number of
  4841.           characters it can contain is 15.  If more than 15 characters are
  4842.           in the name, only the first 15 are saved.
  4843.  
  4844.  
  4845.  
  4846.                                    INSERT-2
  4847.  
  4848.  
  4849.  
  4850.  
  4851.           
  4852.           insert into cust values('GG','Bizzlesnarf & Sons','CA',10);
  4853.           
  4854.           Although the above command would be allowed, when we retrieve the
  4855.           customer name, only "Bizzlesnarf & " would be displayed.
  4856.           
  4857.           Numeric Data
  4858.           The basic rule to remember with numeric data is not to enclose
  4859.           them in quotes as we can see above with the entry for rating. 
  4860.           The length of the column as specified in the create table command
  4861.           must not be exceeded.  Rating was created as numeric(2) which
  4862.           means that the maximum number of digits is 2.  The following
  4863.           insert command would cause an error because the entry for rating
  4864.           contains 3 digits instead of 2:
  4865.           
  4866.           insert into cust values('AA','Compugorp','WA',123);
  4867.           
  4868.           Because of the error, none of the values would be added to the
  4869.           table.
  4870.           
  4871.           Null data
  4872.           I really should not write "null data" or "null value" because the
  4873.           concept of the null means absence of a value.  If we add a
  4874.           customer that has no rating we would do something like:
  4875.           
  4876.           insert into cust values('HH','MagnaMice','AZ',null);
  4877.           
  4878.           There are NO QUOTES enclosing the word null.  Like all other
  4879.           keywords in SQL, it can be in uppercase or lowercase letters. 
  4880.           The null is different from a 0 (zero) in that a null means that
  4881.           there is no rating.  A 0 (zero) means that there IS a rating and
  4882.           the rating is 0.  This idea is further developed when discussing
  4883.           data retrieval in the section on the select command.          
  4884.  
  4885.  
  4886.  
  4887.  
  4888.  
  4889.  
  4890.  
  4891.  
  4892.  
  4893.  
  4894.  
  4895.  
  4896.  
  4897.  
  4898.  
  4899.  
  4900.  
  4901.  
  4902.  
  4903.  
  4904.  
  4905.                                    INSERT-3
  4906.  
  4907.  
  4908.  
  4909.  
  4910.          UPDATE DATA IN A TABLE
  4911.          
  4912.          OVERVIEW
  4913.          The update command is used to change column values in existing
  4914.          rows based on criteria in a search_condition that is accomplished
  4915.          through a where clause. If there where any constraints put on the
  4916.          column values when the table was created such as not null or not
  4917.          null unique, the update command makes sure that the constraints
  4918.          are maintained before the columns are actually updated.  Next to
  4919.          the insert command, it is the most cumbersome to use.  To make
  4920.          updates a bit easier, I made a non-ANSI command which is fully
  4921.          explained in the full documentation.
  4922.          
  4923.          UPDATE SYNTAX
  4924.          
  4925.          UPDATE table_name
  4926.          SET column_name = value [, column_name = value...]
  4927.          WHERE search_condition
  4928.  
  4929.          The value can be a mathmatical expression.
  4930.  
  4931.          EXAMPLES:
  4932.          In the first example, the rating for customer AA is increased 
  4933.          by 5.
  4934.          
  4935.          update cust
  4936.          set rating = rating + 5
  4937.          where code = 'AA';
  4938.          
  4939.          In the example below, the rating for customer CC is changed to a
  4940.          null.
  4941.          
  4942.          update cust
  4943.          set rating = null
  4944.          where code = 'CC';
  4945.          
  4946.          
  4947.          The example below shows how to change the percent defects to 10
  4948.          for a batch of product GC that occurred on July 21, 1987 in
  4949.          Idaho.
  4950.          
  4951.          update manu
  4952.          set defects = 10
  4953.          where date = '07/21/87' and code = 'GC' and mst = 'ID';
  4954.          
  4955.          In the following, two columns are changed.  For customer BB,
  4956.          rating is changed to 14 and the state column is changed to Idaho.
  4957.          
  4958.          update cust
  4959.          set rating = 14, st = 'ID'
  4960.          where code = 'BB';
  4961.  
  4962.          
  4963.  
  4964.                                       UPDATE-1
  4965.  
  4966.  
  4967.  
  4968.  
  4969.  
  4970.          The example below is a bit more involved.  We want to change the
  4971.          rating of branch 2A customers who have purchased above average
  4972.          quantities (overall) to 30. The use of the select command in a
  4973.          where clause is covered in a later section.  
  4974.  
  4975.          update cust
  4976.          set rating = 30 
  4977.          where code in 
  4978.           (select distinct code 
  4979.            from cust, sales
  4980.            where cc=code  
  4981.              and bc='2A'  
  4982.              and qty >
  4983.             (select avg(qty) 
  4984.              from sales)); 
  4985.          
  4986.          COMPONENTS OF UPDATE
  4987.          
  4988.          table_name
  4989.          Any existing table in your database.
  4990.          
  4991.          column_name
  4992.          Any valid column name in the table name accessed, including the
  4993.          column(s) which form the key. 
  4994.           
  4995.          value
  4996.          The value is anything appropriate for the data type of the
  4997.          column.  Any value that would work with the insert command will
  4998.          work with the update command.  As with the insert command, the
  4999.          word null is valid to show that there is no value for the column. 
  5000.          Remember to put quotes around character values.
  5001.          
  5002.          
  5003.          search_condition
  5004.          The section on the select command has more detail on the
  5005.          search_condition that is accomplished with the use of a where
  5006.          clause.  Typically, you want to update a single row.  To update a
  5007.          single row the search_condition must test for the primary key so
  5008.          that will be explained here.  The primary key allows you to
  5009.          uniquely define each row.  The cust table, which is used in most
  5010.          of the examples above, has a primary key based on code.  That is,
  5011.          based on the value in code, we know only a single row will be
  5012.          updated.  
  5013.          
  5014.          Compound keys are discussed in the full documentation.
  5015.  
  5016.  
  5017.  
  5018.  
  5019.  
  5020.  
  5021.  
  5022.  
  5023.                                 UPDATE-2
  5024.  
  5025.  
  5026.          DELETE ROWS FROM A TABLE
  5027.          
  5028.          OVERVIEW
  5029.          The delete command deletes rows based on the criteria in the
  5030.          where clause.  Without a where clause, all the data in the table
  5031.          is deleted.
  5032.          Refer to the section on the select statement for details on the
  5033.          where clause.  The basic difference between the select * and the
  5034.          delete is that with select, the rows are displayed, and with
  5035.          delete, the rows are deleted.  Because of this, it is a smart
  5036.          idea to use the select before you use the delete so you can see
  5037.          the rows that you are going to delete.
  5038.          You can only delete complete rows.  If you want to delete column
  5039.          data within a row, use the update command.
  5040.          
  5041.          SYNTAX
  5042.          
  5043.          DELETE FROM table_name
  5044.          [WHERE search_expression]
  5045.          
  5046.          EXAMPLES:
  5047.          
  5048.          The following shows how to delete all the data from the cust
  5049.          table.
  5050.          
  5051.          delete from cust;
  5052.          
  5053.          The following shows how to delete customers from the cust table
  5054.          whose rating is less than 10.
  5055.          
  5056.          delete from cust
  5057.          where rating < 10;
  5058.          
  5059.          COMPONENTS OF DELETE
  5060.          
  5061.          table_name
  5062.          Any existing table in your database.
  5063.          
  5064.          search_condition
  5065.          The section on the select statement has more detail on the
  5066.          search_condition that is accomplished with a where clause. A
  5067.          simple example is shown above. The command to delete customers
  5068.          whose rating is less than 10 could create some problems if there
  5069.          were customers in the sales table with customer codes that you
  5070.          deleted.  Whenever you delete a row that contains a primary key
  5071.          that is used in another table, problems can arise.  In order to
  5072.          determine whether there are any of those customers in the sales
  5073.          table, you could use the select command as shown below.
  5074.          
  5075.          select *
  5076.          from   sales
  5077.          where  cc in (
  5078.            select code
  5079.            from   cust
  5080.            where  rating < 10);
  5081.  
  5082.                                      DELETE-1
  5083.  
  5084.  
  5085.  
  5086.  
  5087.          
  5088.          To delete all the corresponding rows in the sales table for
  5089.          customers whose rating is less than 10, you would simply take the
  5090.          statement above and replace the "select * from" with "delete" as
  5091.          shown below.
  5092.          
  5093.          delete from sales
  5094.          where  cc in (
  5095.            select code
  5096.            from   cust
  5097.            where  rating < 10);
  5098.          
  5099.          The delete command below shows how to delete all rows in the
  5100.          sales table that do not have a corresponding customer code in the
  5101.          cust table. The not exists is covered in the full documentation.
  5102.          
  5103.          delete from sales
  5104.          where not exists
  5105.              (select *
  5106.               from cust
  5107.               where code = cc);
  5108.          
  5109.          HOW TO RESTORE DATA YOU HAVE JUST DELETED
  5110.          
  5111.          Type it in again!!! (Therefore be very careful when you use this
  5112.          command).
  5113.          
  5114.  
  5115.  
  5116.  
  5117.  
  5118.  
  5119.  
  5120.  
  5121.  
  5122.  
  5123.  
  5124.  
  5125.  
  5126.  
  5127.  
  5128.  
  5129.  
  5130.  
  5131.  
  5132.  
  5133.  
  5134.  
  5135.  
  5136.  
  5137.  
  5138.  
  5139.  
  5140.  
  5141.                                 DELETE-2
  5142.  
  5143.  
  5144.          TUTORIAL
  5145.          
  5146.          OVERVIEW
  5147.          This tutorial will take you through the basics creating a tables,
  5148.          inserting data into a table, updating rows in a table, deleting
  5149.          rows from a table, retrieving data from a table, creating a view
  5150.          of a table and dropping a table.  It is designed to give you a
  5151.      feel for the types of things that SSQL can do.  The detailed 
  5152.      description of the syntax is in the main section of the 
  5153.      documentation.
  5154.          
  5155.          START SSQL
  5156.          From the DOS prompt type SSQL and press ENTER.
  5157.      There will be a Title screen.  The next key you press will be part 
  5158.      of the next action so let's first explore the help screens.
  5159.      The shareware version has full help for the editor.  The version
  5160.      for registered users adds full help for SQL syntax and examples.
  5161.      
  5162.  
  5163.          CREATE THE TABLE
  5164.          Before we can put any data into the table, you need to describe
  5165.          the type(s) of data that it is going to contain.  Often the table
  5166.          we create is referred to as a base table.  Base tables contain
  5167.          actual data which is distinguished from a derived table (see
  5168.          Create a View). It is assumed that you have already read the
  5169.          introduction which contains the basic definitions of columns,
  5170.          rows, and tables. You will create a shortened version of a
  5171.          payroll table.  For each employee you will store the last name,
  5172.          the first name, salary, and city.  The key will be
  5173.          a combination of last name and first name. Type the following:
  5174.          
  5175.          create table pay (
  5176.      code char(2) not null unique,
  5177.          last char(15) not null,
  5178.          first char(15) not null,
  5179.          salary numeric(5),
  5180.          city char(12),
  5181.      tot_sold numeric(7,2)
  5182.          );
  5183.          The employee code is up to two characters long and is the primary
  5184.      key so we are telling it that there must be a value for this column
  5185.      (not null) and each one must be unique. Last name and first name can
  5186.      each be up to fifteen characters in length.  The values for city are 
  5187.      limited to twelve characters.  Salary is limited to five digits 
  5188.      which means up to $99,999. Total items sold is limited to $99,999.99.
  5189.          You can edit the above description until it is correct.  Once it
  5190.          is correct press:
  5191.          F4
  5192.          This will process the command.  If you have correct syntax, there
  5193.          will be a message box in the middle of the screen stating
  5194.          Table Created
  5195.          Otherwise an error message will appear and you can go back and
  5196.      correct it.
  5197.  
  5198.                                 TUTORIAL-1
  5199.  
  5200.  
  5201.          At this point we can either save what we just typed or delete it
  5202.      and type something new.  Let's delete this one and save the next one.
  5203.  
  5204.      What we want to do is quickly delete all the text on the screen.
  5205.      In editor terms, we want to delete a block of text. Let's find out
  5206.      how to do it by looking it up in the help screens.
  5207.  
  5208.          TO ACCESS THE ON-LINE HELP
  5209.      Let's assume that you want to find help on marking and deleting 
  5210.      blocks of text.
  5211.  
  5212.          Press F1.  
  5213.  
  5214.      You will notice the following list with the first item highlighted:
  5215.      Quick Start for SQL Commands
  5216.      Text Editor
  5217.      File
  5218.      Edit
  5219.      Search
  5220.      Window
  5221.      SQL
  5222.  
  5223.      Since marking and deleting text refers to the text editor, press
  5224.      the TAB key once to highlight "Text Editor" and press the ENTER
  5225.      key.
  5226.      The next screen gives some basic information but we want information
  5227.      specifically for blocks.  It is the first item so it is already
  5228.      highlighted.  Press ENTER.
  5229.      It starts with a description of how to mark a block:
  5230.      "Move the cursor to one end of the block.  While holding down the 
  5231.      shift key, use the arrow keys to move to the other end of the block.
  5232.      Now it is marked"
  5233.  
  5234.      In about the middle of the screen, it gives you more than one way to
  5235.      delete a block: Ctrl-KY, Ctrl-Del, or Del.  The reason there is more
  5236.      than one way is to cover a variety of standards.
  5237.  
  5238.      Press ESC to get out of the help screen.
  5239.      
  5240.  
  5241.          Assuming that the cursor is at the end of the command, you can
  5242.          delete the command to create the table by pressing:
  5243.          Shift-PgUp, Del
  5244.          (What it actually does is mark all the text and then you delete the
  5245.          block you marked)
  5246.  
  5247.  
  5248.      Let's create another table which will be need to make joins and 
  5249.      subqueries. Type:
  5250.  
  5251.      create table trans (
  5252.      trans_code numeric(3) not null unique,
  5253.      sales_prsn char(2) not null,
  5254.      prod char(2) not null,
  5255.      qty numeric(3) not null,
  5256.      cost numeric(5,2) not null
  5257.      );
  5258.  
  5259.                                 TUTORIAL-2
  5260.  
  5261.  
  5262.      Notice that the window is untitled (top center of the window).  Let's
  5263.      save it under the file name TRANS.CR.  Do the following:
  5264.          ALT-F <-this means hold down the ALT key and press F
  5265.  
  5266.      Now you are looking at the File screen. The 'a' in "Save As" is
  5267.      highlighted so press the A key.
  5268.  
  5269.      A file name box appears. Type the following and press ENTER:
  5270.      TRANS.CR
  5271.      
  5272.          Now at the top of the window, the name of the file is TRANS.CR. We
  5273.      want to start a new window.  To keep our "desk-top" clean, we should
  5274.      close the existing window before openning a new one. 
  5275.      Press ALT F3 to close the window.
  5276.  
  5277.      To open a new window press ALT-F to get to the file menu and press
  5278.      N to open a new file.
  5279.  
  5280.      Now it is time to put data into the table.  I offer two ways to do
  5281.      it.  Adding data to a table in standard SQL is very cumbersome so
  5282.      I have created a "Form" program to make it easier.  For the PAY table
  5283.      I will use standard SQL.  For the TRANS table, I will use SSQLFORM.
  5284.  
  5285.          INSERT DATA INTO THE TABLE
  5286.          The following has has the commands to insert four rows of data 
  5287.          into the table. When you type them, be careful to include all the
  5288.          appropriate quotes and commas.  And yes, include the incorrect
  5289.          spelling of Scottsdale.  You will correct it in the next section.
  5290.          Note that Hippity Hopper has a null in place of his
  5291.          salary.  This means that the salary is not available which is
  5292.          different from putting a salary of zero.
  5293.  
  5294.          With long commands, it is a better idea to press the F5 to make
  5295.          the text editing full-screen. You can type all of the lines before
  5296.          pressing F4.  However, if there is an error on one of the lines,
  5297.          it will be more difficult to determine which line it is on.
  5298.          
  5299.          insert into pay values('AA','Everski','Willy',45000,'Scottsdale',0);
  5300.          (press F4)
  5301.          (Shift-PgUp,Del)
  5302.          insert into pay values('BB','Everski','Wilshe',60000,'Scootsdale',0);
  5303.          (press F4)
  5304.          (Shift-PgUp,Del)
  5305.          insert into pay values('CC','Hopper','Hippity',null,'Phoenix',0);
  5306.          (press F4)
  5307.          (Shift-PgUp,Del)
  5308.          insert into pay values('DD','Nosebleed','Harvey',20000,'Peoria',0);
  5309.          (press F4)
  5310.          (Shift-PgUp,Del)
  5311.  
  5312.                                 TUTORIAL-3
  5313.  
  5314.  
  5315.          Although the above is SQL syntax, SSQL allows a much easier way
  5316.          to fill the tables with data.  Let's add data to the TRANS table
  5317.      the easy way.  Press
  5318.          ALT-Q
  5319.      to access the SQL menu.  Press
  5320.      F
  5321.          to access the FORMS program which allows flexible data entry.
  5322.          Type TRANS.DBF for the file name.  After you have entered all the
  5323.          data, press ESC to exit the FORMS program.
  5324.  
  5325.          1 
  5326.      AA         
  5327.      r4     
  5328.      3  
  5329.      3.45 
  5330.  
  5331.          2 
  5332.      AA         
  5333.      r6     
  5334.      1  
  5335.      2.50 
  5336.  
  5337.          3 
  5338.      BB         
  5339.      r4     
  5340.      5  
  5341.      6.78 
  5342.  
  5343.  
  5344.          If you made any mistakes, you should be able to correct them
  5345.          after going through the next section on updates.
  5346.          
  5347.          UPDATE DATA IN A TABLE
  5348.          You need to make some changes to the table.  
  5349.      Scootsdale needs to be changed to Scottsdale 
  5350.  
  5351.  
  5352.  
  5353.          update pay
  5354.          set city = 'Scottsdale'
  5355.          where city = 'Scootsdale';
  5356.          
  5357.          (press F4)
  5358.          (Shift-PgUp,Del)
  5359.  
  5360.      The salary for everyone needs to be increased by 10%.
  5361.  
  5362.          update pay
  5363.          set salary = salary * 1.1;
  5364.          
  5365.          (press F4)
  5366.          (Shift-PgUp,Del)
  5367.  
  5368.                                 TUTORIAL-4
  5369.  
  5370.  
  5371.          Let's do something a bit more complex.  Total the sales (cost*qty)
  5372.      by Willy Everski ('AA') from the TRANS table and update the 
  5373.      TOT_SOLD column in the pay table.  To do that type the following:
  5374.          
  5375.      update pay
  5376.      set tot_sold =
  5377.          (select sum(cost*qty) from trans
  5378.           where sales_prsn = 'AA')
  5379.      where code = 'AA';
  5380.  
  5381.          (press F4)
  5382.          (Shift-PgUp,Del)
  5383.  
  5384.          DELETE A ROW FROM A TABLE
  5385.          Harvey Nosebleed has been fired so you want to delete the row
  5386.          that contains the data for Harv.  
  5387.  
  5388.      delete from pay
  5389.          where  last='Nosebleed';
  5390.  
  5391.          (press F4)
  5392.          (Shift-PgUp,Del)
  5393.          
  5394.  
  5395.      In a manner similar to the update, the where clause describes which
  5396.          row should be deleted.
  5397.  
  5398.          
  5399.          RETRIEVE DATA FROM A TABLE
  5400.          The select command is used to retrieve data from a table.  The
  5401.          following select command retrieves all the data in the table. 
  5402.          
  5403.          select *
  5404.          from pay;
  5405.  
  5406.          (press F4)
  5407.          
  5408.      CODE LAST            FIRST           SALARY CITY         TOT_SOLD 
  5409.      ---- --------------- --------------- ------ ------------ -------- 
  5410.      AA   Everski         Willy            49500 Scottsdale      12.85 
  5411.      BB   Everski         Wilshe           66000 Scottsdale       0.00 
  5412.      CC   Hopper          Hippity                Phoenix          0.00 
  5413.  
  5414.  
  5415.  
  5416.          The above is in a text window on the right of the screen.  Notice
  5417.          that the screen is cut off at the salary amount.  The best solution
  5418.          is to press F5 to make the text window full-screen.  (Remember to
  5419.          press F5 again to shrink it).  Otherwise you can move the cursor
  5420.          to the heading line and press the END key to scroll to the end of
  5421.          the line.
  5422.  
  5423.                                 TUTORIAL-5
  5424.  
  5425.  
  5426.          Let's do two optional operations:
  5427.          Edit it.  
  5428.         Add the heading "THE COMPLETE PAY TABLE" at the top of the
  5429.         window.
  5430.          Print it. Press ALT-F,P to print the contents of a text window.
  5431.  
  5432.  
  5433.          Now erase it. Press ALT-F3 to close the window. It will ask whether
  5434.      you want to save the changes.  Press N.
  5435.  
  5436.          (press Shift-PgUp,Del)
  5437.  
  5438.      WHAT HAPPENS WHEN YOU FORGET THE NAMES OF THE COLUMNS
  5439.      Before we go any further, it may be useful to find out the names
  5440.      of the columns in a table.  The struct command will do that for us.
  5441.      Type:
  5442.  
  5443.      struct pay;
  5444.  
  5445.                             COLUMN DECIMAL NOT
  5446.      COLUMN NAME  DATA TYPE  WIDTH  PLACES  NULL  UNIQUE  INDEX
  5447.      CODE         character      3           X       X    
  5448.      LAST         character     15           X            
  5449.      FIRST        character     15           X            
  5450.      SALARY       numeric        5     0                  
  5451.      CITY         character     12                        
  5452.      TOT_SOLD     numeric        7     2                  
  5453.  
  5454.  
  5455.          (press F4)
  5456.      (You won't be able to see all of it in the narrow window so press
  5457.      F5 to zoom the window).
  5458.          (press ALT-F3 to close the window)
  5459.          (Shift-PgUp,Del)
  5460.          
  5461.          The following shows how to retrieve the first name and last name for
  5462.          all the rows.
  5463.          
  5464.          select first, last
  5465.          from pay;
  5466.  
  5467.          (press F4)
  5468.          
  5469.          first           last            
  5470.          --------------- --------------- 
  5471.          Willy           Everski         
  5472.          Wilshe          Everski         
  5473.          Hippity         Hopper          
  5474.          
  5475.  
  5476.          (press ALT-F3 to close the window)
  5477.          (press Shift-PgUp,Del)
  5478.  
  5479.                                 TUTORIAL-6
  5480.  
  5481.  
  5482.          The following displays the rows of employees which
  5483.          have salaries of less than $58,000.  Notice that the row for
  5484.          Hippity Hopper is not displayed because all nulls are excluded. 
  5485.          
  5486.          select *
  5487.          from pay
  5488.          where salary < 58000;
  5489.  
  5490.          (press F4)
  5491.          
  5492.          last          first         salary city         
  5493.          ------------- ------------- ------ ------------ 
  5494.          Everski       Willy          49500 Scottsdale   
  5495.          
  5496.  
  5497.          (press ALT-F3 to close the window)
  5498.          (press Shift-PgUp,Del)
  5499.  
  5500.     *****************************************************************
  5501.     * FROM NOW ON I WILL ASSUME THAT YOU KNOW ABOUT THE F4, ALT-F3, *
  5502.     * AND SHIFT-PGUP, DEL
  5503.     *****************************************************************
  5504.  
  5505.      ELIMINATING DUPLICATE ROWS
  5506.      We can eliminate duplicate rows with the DISTINCT modifier.  The
  5507.      TRANS table has three rows but two of them have duplicate product
  5508.      codes.  We can display a list of all the DIFFERENT product codes
  5509.      with:
  5510.  
  5511.      select distinct prod
  5512.      from trans;
  5513.     
  5514.      prod 
  5515.      ---- 
  5516.      r4   
  5517.      r6   
  5518.     
  5519.      AGGREGATE FUNCTIONS (AVG, MIN, MAX,SUM,COUNT)
  5520.      
  5521.      These functions operate on the whole table so they cannot normally
  5522.      exist with simple column names.
  5523.  
  5524.      The SUM function adds items in a numeric column as in:
  5525.  
  5526.      select sum(salary) 
  5527.      from pay;
  5528.  
  5529.      SUM(salary) 
  5530.      ----------- 
  5531.           115500 
  5532.  
  5533.                                 TUTORIAL-7
  5534.  
  5535.  
  5536.          The COUNT function simply counts the number of rows that have
  5537.      values.  The ones that contain NULL are not counted.  You can
  5538.      use a shortcut with the '*' to count all rows:
  5539.  
  5540.      select count(*)
  5541.      from pay;
  5542.  
  5543.      CNT(*) 
  5544.      ------ 
  5545.           3 
  5546.  
  5547.      However when we count the number of rows with salary, only two 
  5548.      are listed because Hippity Hopper doesn't have a salary.
  5549.  
  5550.      select count(salary)
  5551.      from pay;
  5552.  
  5553.      CNT(salary) 
  5554.      ----------- 
  5555.                2 
  5556.  
  5557.      When you calculate the average salary, it will correctly divide by
  5558.      two, not three:
  5559.  
  5560.      select avg(salary)
  5561.      from pay;
  5562.  
  5563.      AVG(salary) 
  5564.      ----------- 
  5565.            57750 
  5566.  
  5567.  
  5568.  
  5569.          CALCULATIONS
  5570.          You can do calculations but you have to be careful.  It will take
  5571.          us three times to get it the way we want.
  5572.          Let's assume we want to display the qty, cost and the extended cost
  5573.          for each item.  Type:
  5574.  
  5575.  
  5576.          select qty, cost, qty*cost 
  5577.          from trans;
  5578.  
  5579.          qty  cost      qty 
  5580.          --- ----- -------- 
  5581.            3  3.45       10 
  5582.            1  2.50        2 
  5583.            5  6.78       34 
  5584.  
  5585.          Hey! That's not right!  3 * 3.45 is not just 10, it is 10.35. Well,
  5586.          by putting qty first in the list of calculations, it based the 
  5587.          calculation on the data type of qty which is a whole number so
  5588.          the decimal portion did not appear.
  5589.  
  5590.                                 TUTORIAL-8
  5591.  
  5592.  
  5593.          Let's try it again. Type:
  5594.  
  5595.          select qty, cost, cost*qty
  5596.          from trans;
  5597.  
  5598.      qty  cost       cost 
  5599.      --- ----- ---------- 
  5600.        3  3.45      10.35 
  5601.        1  2.50       2.50 
  5602.        5  6.78      33.90 
  5603.  
  5604.      That is better but we need a better heading.  If you don't change
  5605.      the heading, it will be the first column name in the calculation.
  5606.      Let's change the heading to ExtCost:
  5607.  
  5608.          select qty, cost, cost*qty ExtCost
  5609.          from trans;
  5610.  
  5611.      qty  cost      ExtCost 
  5612.      --- ----- ------------ 
  5613.        3  3.45        10.35 
  5614.        1  2.50         2.50 
  5615.        5  6.78        33.90 
  5616.  
  5617.      SORTING THE ROWS
  5618.      Let's print all the rows in the TRANS table but sort them by 
  5619.      product code:
  5620.  
  5621.      select *
  5622.      from trans
  5623.      order by prod;
  5624.  
  5625.      TRANS_CODE SALES_PRSN PROD QTY  COST 
  5626.      ---------- ---------- ---- --- ----- 
  5627.               1 AA         r4     3  3.45 
  5628.               3 BB         r4     5  6.78 
  5629.               2 AA         r6     1  2.50 
  5630.  
  5631.     
  5632.      GROUP INFORMATION
  5633.      Now for something a bit more advanced let's count how many sales
  5634.      EACH salesperson made.  We can see above that AA made two sales
  5635.      and BB made one sale.  We are going to group (re-arrange) the 
  5636.      information by SALES_PRSN and count the number of rows based on
  5637.      each value in the group:
  5638.  
  5639.      select sales_prsn, count(sales_prsn)
  5640.      from trans
  5641.      group by sales_prsn;
  5642.  
  5643.      sales_prsn CNT(sales_prsn) 
  5644.      ---------- --------------- 
  5645.              AA               2 
  5646.              BB               1 
  5647.  
  5648.                                 TUTORIAL-9
  5649.  
  5650.  
  5651.      THE JOIN
  5652.      The power of SQL is seen through the more advanced commands. The
  5653.      join allows us to merge tables.  We need to specify a common column
  5654.      between the tables.  In our example, the column CODE in the pay
  5655.      table describes the same information as SALES_PRSN in the trans
  5656.      table.
  5657.      
  5658.      Let's display the name of the salesperson along with the product
  5659.      code and the quantity sold.
  5660.  
  5661.      select first, last, prod, qty
  5662.      from pay, trans
  5663.      where code=sales_prsn; 
  5664.  
  5665.      first           last            prod qty 
  5666.      --------------- --------------- ---- --- 
  5667.      Willy           Everski         r4     3 
  5668.      Willy           Everski         r6     1 
  5669.      Wilshe          Everski         r4     5 
  5670.  
  5671.     
  5672.      THE SUBQUERY
  5673.      The typical subquery starts processing at the last subquery and 
  5674.      works its way back up. Let's display the names of all salespersons
  5675.      who have sold product which cost less than $5.  The bottom query
  5676.      gathers the codes of persons who have sold products less than $5.
  5677.      That information is passed back to the top query which finds the
  5678.      names based on the codes.
  5679.  
  5680.      select first, last
  5681.      from pay
  5682.      where code in
  5683.         (select sales_prsn
  5684.         from trans
  5685.         where cost < 5);
  5686.  
  5687.  
  5688.  
  5689.      first           last            
  5690.      --------------- --------------- 
  5691.      Willy           Everski         
  5692.  
  5693.          
  5694.  
  5695.          CREATE A VIEW
  5696.          A view is an alternate way of looking at a table or even a
  5697.          combination of tables.  It is also known as a derived table
  5698.          because a view is derived from one or more base tables. We will
  5699.          create a view which excludes salary information.  The view is
  5700.          based on a select statement. The view accesses data in the base
  5701.          table every time it is used in a select statement.  There is
  5702.          never any data contained in the view.  The following creates the view:
  5703.  
  5704.          create view pay1 as
  5705.          select code, last, first, city
  5706.          from pay;
  5707.          (press F4)
  5708.  
  5709.                                 TUTORIAL-10
  5710.  
  5711.  
  5712.          Now let's see what happens when all the columns of the view are
  5713.          selected.
  5714.          
  5715.          select *
  5716.          from pay1;
  5717.          (press F4)
  5718.  
  5719.  
  5720.      CODE LAST            FIRST           CITY         
  5721.      ---- --------------- --------------- ------------ 
  5722.      AA   Everski         Willy           Scottsdale   
  5723.      BB   Everski         Wilshe          Scottsdale   
  5724.      CC   Hopper          Hippity         Phoenix      
  5725.          
  5726.          (press ALT-F3 to close the window)
  5727.          (press Shift-PgUp,Del)
  5728.  
  5729.          DROP A TABLE
  5730.          When a table is dropped, the description of the table is erased
  5731.          from the disk.  The drop command will only work on an empty
  5732.          table.  The delete command is needed to delete all the data in 
  5733.          the table then the drop command erases the table from the disk.  
  5734.          
  5735.          delete from pay;
  5736.          (press F4)
  5737.          (press Shift-PgUp,Del)
  5738.  
  5739.          drop table pay;
  5740.          (press F4)
  5741.          (press Shift-PgUp,Del)
  5742.  
  5743.          drop view pay1;
  5744.          (press F4)
  5745.          (press Shift-PgUp,Del)
  5746.  
  5747.          EXIT SSQL
  5748.          Press ALT-X to exit.  When it asks you whether you want to save
  5749.          the untitled file, press N.
  5750.  
  5751.  
  5752.                                 TUTORIAL-11
  5753.  
  5754.